*** pgsql/src/backend/utils/adt/pg_locale.c.orig 2008-01-01 20:45:52.000000000 +0100 --- pgsql/src/backend/utils/adt/pg_locale.c 2008-02-14 14:24:48.918942700 +0100 *************** *** 72,83 **** #ifdef LC_MESSAGES static char lc_messages_envbuf[LC_ENV_BUFSIZE]; ! #endif static char lc_monetary_envbuf[LC_ENV_BUFSIZE]; static char lc_numeric_envbuf[LC_ENV_BUFSIZE]; static char lc_time_envbuf[LC_ENV_BUFSIZE]; - /* * pg_perm_setlocale * --- 72,156 ---- #ifdef LC_MESSAGES static char lc_messages_envbuf[LC_ENV_BUFSIZE]; ! ! #ifdef WIN32 ! /* ! * GetText internal variable described in GetText docs to force ! * loading a new catalog (locale) ! */ ! __declspec(dllimport) extern int _nl_msg_cat_cntr; ! ! /* ! * Simple record structure to hold the locale_id and the explicit locale values. ! */ ! typedef struct pg_win32_locale ! { ! unsigned long locale_id; ! char* names[10]; ! } pg_win32_locale; ! ! /* ! * Current locales supported in PostgreSQL. It is possible that some of ! * these locale translations are not completed yet by language translators. ! * ! * The values of these locale_ids are extracted from: ! * http://msdn2.microsoft.com/en-us/library/ms776260(VS.85).aspx ! */ ! pg_win32_locale pg_win32_locale_database[] = { ! {0x0436,{"af","af-ZA","af_ZA","Afrikaans_South_Afrika"}}, ! {0x0405,{"cs","cs-CZ","cs_CZ","Czech_Czech_Republic"}}, ! {0x0407,{"de","de-DE","de_DE","German_Germany"}}, ! {0x0c0a,{"es","es-ES","es_ES","Spanish_Spain"}}, ! {0x040c,{"fr","fr-FR","fr_FR","French_France"}}, ! {0x041a,{"hr","hr-HR","hr_HR","Croatian_Croatia"}}, ! {0x040e,{"hu","hu-HU","hu_HU","Hungarian"}}, ! {0x0410,{"it","it-IT","it_IT","Italian_Italy"}}, ! {0x0412,{"ko","ko-KR","ko_KR","Korean_Korea"}}, ! {0x0414,{"nb","nb-NO","nb_NO","Norwegian_bokm�l_Norway"}}, ! {0x0413,{"nl","nl-NL","nl_NL","Dutch_Netherlands"}}, ! {0x0416,{"pt","pt-BR","pt_BR","Portuguese_Brazil"}}, ! {0x0418,{"ro","ro-RO","ro_RO","Romanian_Romania"}}, ! {0x0419,{"ru","ru-RU","ru_RU","Russian_Russia"}}, ! {0x041b,{"sk","sk-SK","sk_SK","Slovak_Slovakia"}}, ! {0x0424,{"sl","sl-SI","sl_SI","Slovenian_Slovenia"}}, ! {0x041d,{"sv","sv-SE","sv_SE","Swedish_Sweden"}}, ! {0x041f,{"tr","tr-TR","tr_TR","Turkish_Turkey"}}, ! {0x0804,{"zh-CN","zh_CN","Chinese_Simplified_China"}}, ! {0x0404,{"zh-TW","zh_TW","Chinese_Traditional_China"}}, ! {0x0409,{"en-US","en_US","English_United_States"}} ! }; ! ! /* ! * Given an explicit locale name, returns Windows locale_id ! */ ! static unsigned long pg_get_win32_locale_from_name(char *locname) ! { ! int i,n; ! char *lname; ! pg_win32_locale *loc; ! ! int num_locales = sizeof(pg_win32_locale_database) / sizeof(pg_win32_locale); ! ! for(i = 0; i < num_locales; i++) ! { ! n = 0; ! loc = (pg_win32_locale_database + i); ! while( (lname = *(loc->names + n) ) != NULL ) ! { ! if(strcmp(locname,lname) == 0) ! return loc->locale_id; ! n++; ! } ! } ! return 0; ! } ! #endif /* WIN32 */ ! #endif /* LC_MESSAGES */ ! static char lc_monetary_envbuf[LC_ENV_BUFSIZE]; static char lc_numeric_envbuf[LC_ENV_BUFSIZE]; static char lc_time_envbuf[LC_ENV_BUFSIZE]; /* * pg_perm_setlocale * *************** *** 100,106 **** #ifndef WIN32 result = setlocale(category, locale); #else ! /* * On Windows, setlocale(LC_MESSAGES) does not work, so just assume that * the given value is good and set it in the environment variables. We --- 173,179 ---- #ifndef WIN32 result = setlocale(category, locale); #else ! unsigned long win32_locale_id; /* * On Windows, setlocale(LC_MESSAGES) does not work, so just assume that * the given value is good and set it in the environment variables. We *************** *** 166,178 **** /* * On Windows, we need to modify both the process environment and the ! * cached version in msvcrt */ if (!SetEnvironmentVariable(envvar, result)) return NULL; if (_putenv(envbuf)) return NULL; ! #endif return result; } --- 239,268 ---- /* * On Windows, we need to modify both the process environment and the ! * cached version in msvcrt. */ if (!SetEnvironmentVariable(envvar, result)) return NULL; if (_putenv(envbuf)) return NULL; ! ! /* ! * If we are setting LC_MESSAGES on Windows, we also need to make sure ! * the locale of the current thread is set properly ! */ ! #ifdef LC_MESSAGES ! win32_locale_id = pg_get_win32_locale_from_name(result); ! ! /* if we have a locale defined in pg_win32_locale_database */ ! if(win32_locale_id != 0) ! { ! SetThreadLocale(win32_locale_id); ! /* force gettext to load the new locale catalog*/ ! ++_nl_msg_cat_cntr; ! } ! #endif /* LC_MESSAGES */ ! ! #endif /* WIN32 */ return result; }