What is the correct Windows setlocale for the United Arab Emirates?

耗尽温柔 提交于 2020-01-07 04:44:28

问题


Dear Arab reader from the United Arab Emirates,

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.

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.

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);    
}

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.

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

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


回答1:


Short answer:

Arabic_U.A.E..1256

Long answer:

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);

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.

Extras:

  1. You can use wmain instead of main:

    int wmain(int argc, WCHAR **argv)
    

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

  2. You should pass a parameter to the printf in usage:

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

    not

    printf("Usage: %s <CRT localename>");
    
  3. You can also go with wprintf in usage, and be Unicode all the way.

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

    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)

  5. 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/

    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)

  6. 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.



来源:https://stackoverflow.com/questions/18520712/what-is-the-correct-windows-setlocale-for-the-united-arab-emirates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!