阿拉伯联合酋长国正确的Windows setlocale是什么? [英] What is the correct Windows setlocale for the United Arab Emirates?

查看:95
本文介绍了阿拉伯联合酋长国正确的Windows setlocale是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自阿拉伯联合酋长国的亲爱的阿拉伯读者,

Dear Arab reader from the United Arab Emirates,

我正在将Linux代码移植到纯Windows的途中.除其他代码外,该代码假装将公历日期(内部为Unix日期)转换为回历日期,并使用阿拉伯联合酋长国的语言环境显示结果.

I am on my way to port my Linux code to pure Windows. This code, among others, is pretending to turn a Gregorian date (internally a Unix date) to an Hijri date and display the result using the Arab United Emirates locale.

我需要您的真正原因是要在Windows及其C运行时下正确设置您所在国家的语言环境.到目前为止,我已经测试了Microsoft明确记录的"Arabic_United Arab Emirates.1256"字符串的许多组合.我所有的尝试都返回null.我面临的问题似乎是阿拉伯联合酋长国所特有的,因为我可以毫无问题地设置它:Arab_Saudi Arabia.1256或Arabic_Egypt.1256.

The true reason why I need you is to correctly set your nation's locale under Windows and its C runtime. So far I have tested many combinations of the "Arabic_United Arab Emirates.1256" string as clearly documented as such by Microsoft. All my attempts returned null. The problem I face seems to be very specific to the United Arab Emirates as I can set with no problem : Arabic_Saudi Arabia.1256 or Arabic_Egypt.1256.

因此,如果那里有一些开发人员拥有在Windows PC上安装的Microsoft Visual Studio套件,他是否愿意在CMD终端下使用以下命令来构建和运行以下纯Windows C代码?

So if there is some developer over there owning the Microsoft Visual Studio suite installed on his Windows PC, would he be kind to build and run the following pure Windows C code with the following commands under a CMD terminal ?

/*
 * File : foo.c
 *
 * To build :
 *   C:\path>vcvars64
 *   C:\path>cl /c /Tp foo.c
 *   C:\path>link /subsystem:console foo.obj kernel32.lib
 *
 * Goal:
 *   find the Windows C locale suited for the United Arab Emirates
 *
 * OS: Microsoft Windows 7 Entreprise N
 */
 #include <windows.h>
 #include <stdio.h>
 #include <locale.h>

 void usage(char *str)
 {
    printf("Usage: %s <CRT localename>");
    exit(EXIT_FAILURE);
 }

 int main(int argc, char **argv)
 {
   wchar_t localename[100];

   if (argc != 2) usage(argv[0]);
   MultiByteToWideChar(CP_UTF8, 0, argv[1], -1, localename, sizeof(localename));
   wprintf(L"%s\n",_wsetlocale(LC_TIME,localename));
   exit(EXIT_SUCCESS);    
}

如果您将区域和语言Windows"设置(控制面板")设置为阿拉伯语(阿拉伯联合酋长国),则应使用以下代码运行代码:

Provided your Regional and Language Windows settings (Control Panel) are set to Arabic (United Arab Emirates), then you should run the code with:

C:\path>foo ""

并回复您所读内容的帖子.

and reply to this post with what you read.

在Windows 7上以及Windows区域设置下,上述代码和今晚提供的CMD命令向我显示:"French_France.1252"

On my Windows 7 and with my Windows regional settings, the code above and the provided CMD commands tonight display me: "French_France.1252"

我确实害怕将自己的笔记本变成阿拉伯语(阿拉伯联合酋长国).我是一个纯正的法国公民,试图通过他的公共网站来最好地满足全球IT社区的需求.绝对不会给我介绍任何阿拉伯语言,甚至不会介绍阿拉伯地区方言.我真的很担心,如果我将区域设置更改为您的国家/地区设置,则必须肯定要告别Windows.我的Windows笔记本已经预装了Windows.因此,没有CD可以重新安装Windows.

I do fear to turn myself my Notebook to Arabic (United Arab Emirates). I am a pure French citizen trying to best satisfy the worldwide IT community through his public Web site. I am absolutely not introduced to any Arabic language, even more an Arabic regional dialect. I do really fear that I shall have to definitely say goodbye to Windows if I turn my regional settings to your country settings. My Windows Notebook has been shipped with Windows pre-installed. So no CD to reinstall Windows.

对于此帖子的任何回复者,在此先感谢您.如果带来了预期的答案,甚至更多,如果可能的话,解决方案.

To any replier to this post, many thanks in advance to you. Much more if you bring the expected answer, if possible the solution.

Philippe Vouters

Philippe Vouters

推荐答案

简短答案:

阿拉伯文U.A.E..1256

Arabic_U.A.E..1256

详细答案:

BOOL CALLBACK EnumLocalesProcEx(LPWSTR lpLocaleId, DWORD dwFlags, LPARAM lParam) {
    WCHAR name[10];
    if (GetLocaleInfoEx(lpLocaleId, LOCALE_SABBREVLANGNAME, name, _countof(name))) {
        WCHAR *crtLocale = _wsetlocale(LC_TIME, name);
        wprintf(L"%s   %s    %s\n", lpLocaleId, name, crtLocale);
    }
    return TRUE;
}
...
EnumSystemLocalesEx(EnumLocalesProcEx, LOCALE_ALL, 0, NULL);

这将为您提供所有支持的语言环境的完整列表. (或者,当然,保存/还原原始语言环境会很好,因为该_wsetlocale会弄乱它.

This will give you a complete list of all the locales supported. (or course, it would be nice to save/restore the original locale, because it will be messed up by that _wsetlocale.

其他:

  1. 您可以使用wmain代替main:

  1. You can use wmain instead of main:

int wmain(int argc, WCHAR **argv)

这样,您可以调用_wsetlocale(LC_TIME,argv [1]),不需要MultiByteToWideChar.

That way you can call _wsetlocale(LC_TIME, argv[1]), no need for MultiByteToWideChar.

您应该在使用中将参数传递给printf:

You should pass a parameter to the printf in usage:

printf("Usage: %s <CRT localename>", str);

不是

printf("Usage: %s <CRT localename>");

  • 您还可以在使用wprintf时使用它,并始终使用Unicode.

  • You can also go with wprintf in usage, and be Unicode all the way.

    您可能想看看使用通用文本映射" http://msdn.microsoft.com/en-us/library/7dzey6h6.aspx

    You might want to take a look at "Using Generic-Text Mappings" http://msdn.microsoft.com/en-us/library/7dzey6h6.aspx

    使用_tprintf代替printf/wprintf可能使您有机会在Windows/Linux之间重用代码(尽管POSIX国际支持很差)

    Using things like _tprintf instead of printf/wprintf might give you a chance to reuse code between Windows/Linux (although the POSIX international support is quite poor)

    您可能想在本文+工具上抢劫:

    You might want to take a loot at this article + tool: http://mihai-nita.net/2007/12/19/tounicode-automating-some-of-the-steps-of-unicode-code-conversion-windows/

    它可以帮助您迁移代码以使用Generic-Text函数. (这样,您可以定义UNICODE和_UNICODE并获得完整的Unicode应用程序)

    It might help you migrate your code to use the Generic-Text functions. (that way you can define UNICODE and _UNICODE and get a fully Unicode application)

    不要指望Windows控制台带来奇迹.众所周知,它在渲染外来字符串方面很差.您必须将系统区域设置设置为获得良好的结果.

    Don't expect wonders from the Windows console. It is notoriously poor at rendering foreign strings. You will have to set the system locale get decent results.

    这篇关于阿拉伯联合酋长国正确的Windows setlocale是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆