gbrainy r445 - trunk/src



Author: jmas
Date: Thu Aug 28 13:25:31 2008
New Revision: 445
URL: http://svn.gnome.org/viewvc/gbrainy?rev=445&view=rev

Log:
Fixes numbering formatting display for some locales

Modified:
   trunk/src/ChangeLog
   trunk/src/gbrainy.cs

Modified: trunk/src/gbrainy.cs
==============================================================================
--- trunk/src/gbrainy.cs	(original)
+++ trunk/src/gbrainy.cs	Thu Aug 28 13:25:31 2008
@@ -26,7 +26,8 @@
 using Gnome;
 using Mono.Unix;
 using System.Text;
-
+using System.Globalization;
+using System.Threading;
 
 public class gbrainy: Program
 {
@@ -59,6 +60,7 @@
 		Gdk.Color color;
 
 		Catalog.Init ("gbrainy", Defines.GNOME_LOCALE_DIR);
+		FixLocaleInfo ();
 
 		IconFactory icon_factory = new IconFactory ();
                 AddIcon (icon_factory, "logic-games", "logic-games-32.png");
@@ -149,6 +151,71 @@
 		//OnMemoryOnly (this, EventArgs.Empty); // temp
 	}
 
+		/* Taken from locale.h  */
+		[StructLayout (LayoutKind.Sequential)]
+		public struct lconv
+		{
+			public string decimal_point;
+			public string thousands_sep;		
+			public string grouping;
+			public string int_curr_symbol;
+			public string currency_symbol;
+			public string mon_decimal_point;
+			public string mon_thousands_sep;
+			public string mon_grouping;
+			public string positive_sign;
+			public string negative_sign;
+			char int_frac_digits;
+			char frac_digits;
+			char p_cs_precedes;
+			char p_sep_by_space;
+			char n_cs_precedes;
+			char n_sep_by_space;
+			char p_sign_posn;
+			char n_sign_posn;
+			char int_p_cs_precedes;
+			char int_p_sep_by_space;
+			char int_n_cs_precedes;
+			char int_n_sep_by_space;
+			char int_p_sign_posn;
+			char int_n_sign_posn;
+		}
+
+
+	[DllImport("libc")]
+	static extern IntPtr localeconv ();
+
+	// Mono supports less locales that Unix systems
+	// To overcome this limitation we setup the right locale parameters
+	// when the Mono locale is InvariantCulture, that is, when the user's locale
+	// has not been identified and the default Mono locale is used
+	//
+	// See: https://bugzilla.novell.com/show_bug.cgi?id=420468
+	// 
+	private void FixLocaleInfo ()
+	{
+		IntPtr st;
+		lconv lv;
+		int platform = (int) Environment.OSVersion.Platform;
+		
+		if (platform != 4 && platform != 128) // Only in Unix based systems
+			return;
+
+		if (CultureInfo.CurrentCulture != CultureInfo.InvariantCulture) // Culture well supported
+			return;
+
+		try {
+			st = localeconv ();
+			if (st == null) return;
+
+			lv = (lconv) Marshal.PtrToStructure (st, typeof (lconv));
+			CultureInfo culture =  (CultureInfo) CultureInfo.CurrentCulture.Clone ();
+			culture.NumberFormat.NumberDecimalSeparator = lv.decimal_point;
+			Thread.CurrentThread.CurrentCulture = culture;
+		}
+		catch (Exception) {}
+	}
+
 	public void UpdateStatusBar ()
 	{
 		statusbar.Push (0, session.StatusText);



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