From: Bruno Haible Date: Tue, 13 Jan 2004 12:17:17 +0000 (+0000) Subject: Work around mono-0.29 CurrentUICulture bug. X-Git-Tag: v0.14~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b2b2fcbfedd54254e47f1e33aa365ac799f2dda;p=thirdparty%2Fgettext.git Work around mono-0.29 CurrentUICulture bug. --- diff --git a/gettext-tools/examples/ChangeLog b/gettext-tools/examples/ChangeLog index 12a66deda..7afe8a4df 100644 --- a/gettext-tools/examples/ChangeLog +++ b/gettext-tools/examples/ChangeLog @@ -1,3 +1,8 @@ +2004-01-10 Bruno Haible + + * hello-csharp/hello.cs: Work around mono-0.29 CurrentUICulture bug. + * hello-csharp-forms/hello.cs: Likewise. + 2003-12-29 Bruno Haible * hello-perl/INSTALL: Mention that libintl-perl-1.09 required. diff --git a/gettext-tools/examples/hello-csharp-forms/hello.cs b/gettext-tools/examples/hello-csharp-forms/hello.cs index ed8568caf..bb344fb67 100644 --- a/gettext-tools/examples/hello-csharp-forms/hello.cs +++ b/gettext-tools/examples/hello-csharp-forms/hello.cs @@ -1,5 +1,5 @@ // Example for use of GNU gettext. -// Copyright (C) 2003 Free Software Foundation, Inc. +// Copyright (C) 2003-2004 Free Software Foundation, Inc. // This file is in the public domain. // // Source code of the C#/Forms program. @@ -77,6 +77,20 @@ public class Hello { } public static void Main () { + #if __MonoCS__ + // Some systems don't set CurrentCulture and CurrentUICulture as specified + // by LC_ALL. So set it by hand. + String locale = System.Environment.GetEnvironmentVariable("LC_ALL"); + if (locale == null || locale == "") + locale = System.Environment.GetEnvironmentVariable("LANG"); + if (!(locale == null || locale == "")) { + if (locale.IndexOf('.') >= 0) + locale = locale.Substring(0,locale.IndexOf('.')); + System.Threading.Thread.CurrentThread.CurrentCulture = + System.Threading.Thread.CurrentThread.CurrentUICulture = + new System.Globalization.CultureInfo(locale.Replace('_','-')); + } + #endif Application.Run(new HelloWindow()); } } diff --git a/gettext-tools/examples/hello-csharp/hello.cs b/gettext-tools/examples/hello-csharp/hello.cs index 1454990b6..ce3c3b8cf 100644 --- a/gettext-tools/examples/hello-csharp/hello.cs +++ b/gettext-tools/examples/hello-csharp/hello.cs @@ -1,5 +1,5 @@ // Example for use of GNU gettext. -// Copyright (C) 2003 Free Software Foundation, Inc. +// Copyright (C) 2003-2004 Free Software Foundation, Inc. // This file is in the public domain. // // Source code of the C# program. @@ -10,6 +10,20 @@ using System.Diagnostics; /* Process */ public class Hello { public static void Main (String[] args) { + #if __MonoCS__ + // Some systems don't set CurrentCulture and CurrentUICulture as specified + // by LC_ALL. So set it by hand. + String locale = System.Environment.GetEnvironmentVariable("LC_ALL"); + if (locale == null || locale == "") + locale = System.Environment.GetEnvironmentVariable("LANG"); + if (!(locale == null || locale == "")) { + if (locale.IndexOf('.') >= 0) + locale = locale.Substring(0,locale.IndexOf('.')); + System.Threading.Thread.CurrentThread.CurrentCulture = + System.Threading.Thread.CurrentThread.CurrentUICulture = + new System.Globalization.CultureInfo(locale.Replace('_','-')); + } + #endif GettextResourceManager catalog = new GettextResourceManager("hello-csharp"); Console.WriteLine(catalog.GetString("Hello, world!")); diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index e943097ae..28ad914c5 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,7 @@ +2004-01-10 Bruno Haible + + * lang-csharp: Work around mono-0.29 CurrentUICulture bug. + 2003-12-29 Bruno Haible * testlocale.c: Include stdlib.h. diff --git a/gettext-tools/tests/lang-csharp b/gettext-tools/tests/lang-csharp index e05cc2fbf..424c7fc49 100755 --- a/gettext-tools/tests/lang-csharp +++ b/gettext-tools/tests/lang-csharp @@ -5,7 +5,8 @@ # Assumes the following packages are installed: pnet, pnetlib. # Note: This test fails with mono-0.28 because the CultureInfo.Parent pointers -# are wrong for locales containing a language and a territory. +# are wrong for locales containing a language and a territory. This is fixed +# in mono-0.29. tmpfiles="" trap 'rm -fr $tmpfiles' 1 2 3 15 @@ -19,13 +20,13 @@ using System; using GNU.Gettext; class Program { static void Main (String[] args) { -#if not_yet_needed + #if __MonoCS__ // Some systems don't set CurrentCulture and CurrentUICulture as specified // by LC_ALL. So set it by hand. System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR"); -#endif + #endif int n = Int32.Parse(args[0]); GettextResourceManager catalog = new GettextResourceManager("prog"); Console.WriteLine(catalog.GetString("'Your command, please?', asked the waiter."));