How to set GTK/App locale in Windows?



Goran =?utf-8?q?Raki=C4=87?= writes:
In Linux all works great. This code selectes GTK/App locale based
on user settings (locale var). But in Windows setlocale(LC_ALL,
locale) returns NULL and locale is not selected!

True. The setlocale function in the Microsoft C runtime doesn't return
Unixish "de_DE" style locale names. Instead it returns strings like
"Swedish_Finland.1252" (for my locale, for instance). It does,
however, accept *some* two-letter abbreviations for locales, but,
shock and horror, they are not always the standard ones as used on
modern Unixish systems. There are even clashes: the Microsoft
setlocale() takes "es" to mean Estonian, while the ISO-639 code "es"
mans Spanish... Ouch! And it accepts even ambiguous abbreviations, for
instance "slov" is interpreted to mean Slovak, even if it would also
match Slovenian (and maybe other language names).

How can I load GTK/application locale in Windows, and is the "de_DE" right 
value for German locale to be passed to setlocale()?

GTK on Windows looks at the environment variables LC_ALL, LC_CTYPE and
LANG (even if the Microsoft C runtime doesn't use these at all). So
would it be possible for you to use one of those? You could set the
env var in your code, calling putenv("LANG=de_DE") before calling
gtk_init() should work.

Note that this won't affect the locale used by the C runtime. As you
call gtk_disable_setlocale(), GTK will not call setlocale(LC_ALL, ""),
and thus the C runtime's locale will stay as "C", methinks.

(Here is a test program I once hacked together to check how the
Microsoft locale stuff behaves...

#include <stdio.h>
#include <locale.h>
#include <string.h>

static struct
{
  const char *alpha2, *name;
} iso639[] = {
  {"aa", "Afar"},
  {"ab", "Abkhazian"},
  {"af", "Afrikaans"},
  {"am", "Amharic"},
  {"ar", "Arabic"},
  {"as", "Assamese"},
  {"ay", "Aymara"},
  {"az", "Azerbaijani"},
  {"ba", "Bashkir"},
  {"be", "Byelorussian"},
  {"bg", "Bulgarian"},
  {"bh", "Bihari"},
  {"bi", "Bislama"},
  {"bn", "Bengali; Bangla"},
  {"bo", "Tibetan"},
  {"br", "Breton"},
  {"ca", "Catalan"},
  {"co", "Corsican"},
  {"cs", "Czech"},
  {"cy", "Welsh"},
  {"da", "danish"},
  {"de", "german"},
  {"dz", "Bhutani"},
  {"el", "Greek"},
  {"en", "English"},
  {"eo", "Esperanto"},
  {"es", "Spanish"},
  {"et", "Estonian"},
  {"eu", "Basque"},
  {"fa", "Persian"},
  {"fi", "Finnish"},
  {"fj", "Fiji"},
  {"fo", "Faeroese"},
  {"fr", "French"},
  {"fy", "Frisian"},
  {"ga", "Irish"},
  {"gd", "Scots Gaelic"},
  {"gl", "Galician"},
  {"gn", "Guarani"},
  {"gu", "Gujarati"},
  {"ha", "Hausa"},
  {"hi", "Hindi"},
  {"hr", "Croatian"},
  {"hu", "Hungarian"},
  {"hy", "Armenian"},
  {"ia", "Interlingua"},
  {"ie", "Interlingue"},
  {"ik", "Inupiak"},
  {"in", "Indonesian"},
  {"is", "Icelandic"},
  {"it", "Italian"},
  {"iw", "Hebrew"},
  {"ja", "Japanese"},
  {"ji", "Yiddish"},
  {"jw", "Javanese"},
  {"ka", "Georgian"},
  {"kk", "Kazakh"},
  {"kl", "Greenlandic"},
  {"km", "Cambodian"},
  {"kn", "Kannada"},
  {"ko", "Korean"},
  {"ks", "Kashmiri"},
  {"ku", "Kurdish"},
  {"ky", "Kirghiz"},
  {"la", "Latin"},
  {"ln", "Lingala"},
  {"lo", "Laothian"},
  {"lt", "Lithuanian"},
  {"lv", "Latvian, Lettish"},
  {"mg", "Malagasy"},
  {"mi", "Maori"},
  {"mk", "Macedonian"},
  {"ml", "Malayalam"},
  {"mn", "Mongolian"},
  {"mo", "Moldavian"},
  {"mr", "Marathi"},
  {"ms", "Malay"},
  {"mt", "Maltese"},
  {"my", "Burmese"},
  {"na", "Nauru"},
  {"ne", "Nepali"},
  {"nl", "Dutch"},
  {"no", "Norwegian"},
  {"oc", "Occitan"},
  {"om", "(Afan) Oromo"},
  {"or", "Oriya"},
  {"pa", "Punjabi"},
  {"pl", "Polish"},
  {"ps", "Pashto, Pushto"},
  {"pt", "Portuguese"},
  {"qu", "Quechua"},
  {"rm", "Rhaeto-Romance"},
  {"rn", "Kirundi"},
  {"ro", "Romanian"},
  {"ru", "Russian"},
  {"rw", "Kinyarwanda"},
  {"sa", "Sanskrit"},
  {"sd", "Sindhi"},
  {"sg", "Sangro"},
  {"sh", "Serbo-Croatian"},
  {"si", "Singhalese"},
  {"sk", "Slovak"},
  {"sl", "Slovenian"},
  {"sm", "Samoan"},
  {"sn", "Shona"},
  {"so", "Somali"},
  {"sq", "Albanian"},
  {"sr", "Serbian"},
  {"ss", "Siswati"},
  {"st", "Sesotho"},
  {"su", "Sudanese"},
  {"sv", "Swedish"},
  {"sw", "Swahili"},
  {"ta", "Tamil"},
  {"te", "Telugu"},
  {"tg", "Tajik"},
  {"th", "Thai"},
  {"ti", "Tigrinya"},
  {"tk", "Turkmen"},
  {"tl", "Tagalog"},
  {"tn", "Setswana"},
  {"to", "Tonga"},
  {"tr", "Turkish"},
  {"ts", "Tsonga"},
  {"tt", "Tatar"},
  {"tw", "Twi"},
  {"uk", "Ukrainian"},
  {"ur", "Urdu"},
  {"uz", "Uzbek"},
  {"vi", "Vietnamese"},
  {"vo", "Volapuk"},
  {"wo", "Wolof"},
  {"xh", "Xhosa"},
  {"yo", "Yoruba"},
  {"zh", "Chinese"},
  {"zu", "Zulu"}
};

int
main (int argc, char **argv)
{
  int i;
  char *locale;

#define TEST(l) locale = setlocale (LC_CTYPE, l), printf ("setlocale(LC_CTYPE, \"%s\") = %s\n", l, locale ? 
locale : "NULL")

  TEST("");

  for (i = 0; i < sizeof (iso639) / sizeof (iso639[0]); i++)
    {
      char *underscore;
      int n;

      TEST (iso639[i].alpha2);
      if (locale != NULL)
        {
          underscore = strchr (locale, '_');
          if (underscore)
            n = underscore - locale;
          else
            n = strlen (locale);
          if (strnicmp (locale, iso639[i].name, n))
            printf ("  Mismatch! Should be %s\n", iso639[i].name);
        }
    }

  TEST("Polish");
  TEST("Poli");
  TEST("slo");
  TEST("slov");
  TEST("slova");
  TEST("slovak");
  TEST("slove");
  TEST("slovenian");

  return 0;
}
)


--tml





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]