Hereby a patch that fixes NLS support on PG 8.3 compiled with MSVC. There problem:
NLS support does not work on PG 8.3 compiled with MSVC. I encountered this bug when I was trying to show localized months and days using TO_CHAR. The main reason for this problem is because Gettext on Windows does not respond to LC_MESSAGES environment variable. Changing this variable should trigger Gettext to load a different messages catalog which unfortunately does not work on Windows. Gettext uses the locale of the current thread in execution to determine which message catalog should be loaded. This is all discussed in: http://archives.postgresql.org/pgsql-hackers/2008-02/msg00485.php How it is fixed: Changing the LC_MESSAGES is done in pg_locale.c::pg_perm_setlocale(int category, const char *locale). In order to force Gettext to load a messages catalog we have to call WIN32API::SetThreadLocale(unsigned long locale_id) (You probably see it coming) Our input parameter for locale in pg_perm_setlocale is a string and there is no unified way in Windows to translate a locale string to a locale_id for SetThreadLocale to use. Therefore we will use a static table of values to anticipate the locale name: pg_win32_locale_database::{0x041b,{"sk","sk-SK","sk_SK","Slovak_Slovakia"}} Given any of "sk","sk-SK","sk_SK".... the 0x041b is returned for SetThreadLocale as input parameter. (We are not quite done yet) Gettext, internally uses a hack to force itself to reload. This hidden feature is also explained in GetText docs. By incrementing a Gettext internal variable (_nl_msg_cat_cntr) we force Gettext to reload on the next LC_MESSAGES->MSGID query. Tests: - Tested on Win XP MSVC (VC++ 8.0) - Just a routine "make check" test on my Linux box - MINGW is not tested. (I do not have the installation) Fix notes: - Gettext behaves oddly when the env. variable LANGUAGE is set before starting PG - The locale names in the static table are case sensitive. 'nl_NL' != 'NL_NL' - At this moment I only have included locale names we actually support in PG installation. - Where are the JP locale .po and .mo files? These are not in sources! - Even though there are 20+ locales in PG installation, does not mean those are complete. Try TMMonth,TMDay on "nl_NL". You will get English names :) (My fault, hee hee, I haven't completed nl.po translations yet.) TODO: - Provide/complete the day and month names for all supported locales. - Create docs for supported locale names on Windows. (Values of the static table) Regards, Gevik Babakhani ------------------------------------------------ PostgreSQL NL http://www.postgresql.nl TrueSoftware BV http://www.truesoftware.nl ------------------------------------------------
1.pg_locale.c.patch
Description: Binary data
Welcome to psql 8.3.0, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
Warning: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Gevik=# set lc_messages to 'sv_SE';
SET
Gevik=# select to_char((current_date + s.a),'TMDay TMMonth YYYY') as dates from
generate_series(0,6) as s(a);
dates
-----------------------
Torsdag Februari 2008
Fredag Februari 2008
L÷rdag Februari 2008
S÷ndag Februari 2008
MÏndag Februari 2008
Tisdag Februari 2008
Onsdag Februari 2008
(7 rows)
Gevik=# set lc_messages to 'de_DE';
SET
Gevik=# select to_char((current_date + s.a),'TMDay TMMonth YYYY') as dates from
generate_series(0,6) as s(a);
dates
-------------------------
Donnerstag Februar 2008
Freitag Februar 2008
Samstag Februar 2008
Sonntag Februar 2008
Montag Februar 2008
Dienstag Februar 2008
Mittwoch Februar 2008
(7 rows)
Gevik=# set lc_messages to 'English_United_States';
SET
Gevik=# select to_char((current_date + s.a),'TMDay TMMonth YYYY') as dates from
generate_series(0,6) as s(a);
dates
-------------------------
Thursday February 2008
Friday February 2008
Saturday February 2008
Sunday February 2008
Monday February 2008
Tuesday February 2008
Wednesday February 2008
(7 rows)
Gevik=# set lc_messages to 'tr-TR';
SET
Gevik=# select to_char((current_date + s.a),'TMDay TMMonth YYYY') as dates from
generate_series(0,6) as s(a);
dates
----------------------
Persembe Subat 2008
Cuma Subat 2008
Cumartesi Subat 2008
Pazar Subat 2008
Pazartesi Subat 2008
Sali Subat 2008
âarsamba Subat 2008
(7 rows)
Gevik=# set lc_messages to 'fr';
SET
Gevik=# select to_char((current_date + s.a),'TMDay TMMonth YYYY') as dates from
generate_series(0,6) as s(a);
dates
-----------------------
Jeudi FÎvrier 2008
Vendredi FÎvrier 2008
Samedi FÎvrier 2008
Dimanche FÎvrier 2008
Lundi FÎvrier 2008
Mardi FÎvrier 2008
Mercredi FÎvrier 2008
(7 rows)
Gevik=#
---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings
