diff options
author | Lluis Sanchez <llsan@microsoft.com> | 2016-09-06 22:22:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-06 22:22:45 +0300 |
commit | 105cb64488156fa2754873755a5c7dfe428bd22c (patch) | |
tree | 2c623794f016e4ef5482dabb3bcbeaa410ec5cf1 | |
parent | 157520c0cc3decccb96f6321321a340d7e0f8381 (diff) | |
parent | e3a86a3a61580a18b4059d8b4e2f08e0451fac58 (diff) |
Merge pull request #1612 from mono/cycle8-fixup-locale-sierra
[Stub] Implement support for hijacking language if none is set in XS.
-rw-r--r-- | main/build/MacOSX/monostub.m | 21 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Core/Gettext.cs | 50 |
2 files changed, 49 insertions, 22 deletions
diff --git a/main/build/MacOSX/monostub.m b/main/build/MacOSX/monostub.m index 9fab7b3dda..0014a0ff01 100644 --- a/main/build/MacOSX/monostub.m +++ b/main/build/MacOSX/monostub.m @@ -14,6 +14,8 @@ #include "monostub-utils.h" +#import <Foundation/Foundation.h> + typedef int (* mono_main) (int argc, char **argv); typedef void (* mono_free) (void *ptr); typedef char * (* mono_get_runtime_build_info) (void); @@ -210,6 +212,24 @@ run_md_bundle (NSString *appDir, NSArray *arguments) exit (0); } +static void +correct_locale(void) +{ + NSString *preferredLanguage; + + preferredLanguage = [[NSLocale preferredLanguages] objectAtIndex: 0]; + // Apply fixups such as zh_HANS/HANT -> zh_CN/TW + // Strip other languages of remainder so we choose a generic culture. + if ([preferredLanguage caseInsensitiveCompare:@"zh-hans"] == NSOrderedSame) + preferredLanguage = @"zh_CN"; + else if ([preferredLanguage caseInsensitiveCompare:@"zh-hant"] == NSOrderedSame) + preferredLanguage = @"zh_TW"; + else + preferredLanguage = [[preferredLanguage componentsSeparatedByString:@"-"] objectAtIndex:0]; + + setenv("MONODEVELOP_STUB_LANGUAGE", [preferredLanguage UTF8String], 1); +} + int main (int argc, char **argv) { //clock_t start = clock(); @@ -280,6 +300,7 @@ int main (int argc, char **argv) return execv (argv[0], argv); } + correct_locale(); //printf ("Running main app.\n"); if (getrlimit (RLIMIT_NOFILE, &limit) == 0 && limit.rlim_cur < 1024) { diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Gettext.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Gettext.cs index f703ee93a9..30195d6cfe 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Gettext.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Gettext.cs @@ -63,6 +63,29 @@ namespace MonoDevelop.Core { "zh_TW", "zh-TW" },
};
+ static void SetLocale (string locale)
+ {
+ string cultureLang; + if (!localeToCulture.TryGetValue (locale, out cultureLang)) + cultureLang = locale.Replace ("_", "-"); + CultureInfo ci = CultureInfo.GetCultureInfo (cultureLang); + if (ci.IsNeutralCulture) { + // We need a non-neutral culture + foreach (CultureInfo c in CultureInfo.GetCultures (CultureTypes.AllCultures & ~CultureTypes.NeutralCultures)) + if (c.Parent != null && c.Parent.Name == ci.Name && c.LCID != LOCALE_CUSTOM_UNSPECIFIED) { + ci = c; + break; + } + } + if (!ci.IsNeutralCulture) { + if (Platform.IsWindows) + SetThreadUILanguage (ci.LCID); + mainThread.CurrentUICulture = ci; + } + if (!Platform.IsWindows) + Environment.SetEnvironmentVariable ("LANGUAGE", locale);
+ }
+
static GettextCatalog ()
{
mainThread = Thread.CurrentThread;
@@ -71,28 +94,11 @@ namespace MonoDevelop.Core string catalog = Environment.GetEnvironmentVariable ("MONODEVELOP_LOCALE_PATH");
// Set the user defined language
- UILocale = Runtime.Preferences.UserInterfaceLanguage;
- if (!string.IsNullOrEmpty (UILocale)) {
- string cultureLang;
- if (!localeToCulture.TryGetValue (UILocale, out cultureLang))
- cultureLang = UILocale.Replace ("_", "-");
- CultureInfo ci = CultureInfo.GetCultureInfo (cultureLang);
- if (ci.IsNeutralCulture) {
- // We need a non-neutral culture
- foreach (CultureInfo c in CultureInfo.GetCultures (CultureTypes.AllCultures & ~CultureTypes.NeutralCultures))
- if (c.Parent != null && c.Parent.Name == ci.Name && c.LCID != LOCALE_CUSTOM_UNSPECIFIED) {
- ci = c;
- break;
- }
- }
- if (!ci.IsNeutralCulture) {
- if (Platform.IsWindows)
- SetThreadUILanguage (ci.LCID);
- mainThread.CurrentUICulture = ci;
- }
- if (!Platform.IsWindows)
- Environment.SetEnvironmentVariable ("LANGUAGE", UILocale);
- }
+ var locale = UILocale = Runtime.Preferences.UserInterfaceLanguage;
+ if (string.IsNullOrEmpty (UILocale))
+ locale = Environment.GetEnvironmentVariable ("MONODEVELOP_STUB_LANGUAGE");
+ if (!string.IsNullOrEmpty (locale))
+ SetLocale (locale);
if (string.IsNullOrEmpty (catalog) || !Directory.Exists (catalog)) {
string location = System.Reflection.Assembly.GetExecutingAssembly ().Location;
|