Feature request: Native localization function
Monkey Forums/Monkey Programming/Feature request: Native localization function
| ||
I would need to have a way to determine wich language to show in my games and apps. I think something like "GetLocale" that culd return: en, spa, it, etc... to determine the language would be more than welcome. I supose there are native ways to do this in all platforms so, all in all, I miss a lot a sort of mojo.GetLocale. I'm going to release my IdealWeightControl app in Turkish and I would love to avoid having to release it as a separate application, when it can just show itself in the device language. If there's any third-party way to do it, I'm all ears, but I do really thing this is something that should be part of the official release. Not having a basic localization mechanism on a multi-platform multi-target language is very strange. |
| ||
That's the required function on Android: Locale.getDefault().getLanguage();Source: http://stackoverflow.com/questions/4212320/get-the-current-language-in-device That's for iOS: NSString *currentLanguage = [[NSLocale preferredLanguages] objectAtIndex:0];Source: http://stackoverflow.com/questions/6829448/ios-how-to-get-the-device-current-language-setting not sure for Desktop and the rest of devices. If anyone has a working solution for other targets |
| ||
Flash:import flash.system.Capabilities; // ... var lang:String = Capabilities.language;Source: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html#language |
| ||
HTML5 (also supports Android Browser):var lang; if (navigator && navigator.userAgent && (lang = navigator.userAgent .match(/android.*\W(\w\w)-(\w\w)\W/i))) { lang = lang[1]; // Android } if (!lang && navigator) { if (navigator.language) { lang = navigator.language; // cross-browser } else if (navigator.browserLanguage) { lang = navigator.browserLanguage; // IE browser language } else if (navigator.systemLanguage) { lang = navigator.systemLanguage; // Windows system language } else if (navigator.userLanguage) { lang = navigator.userLanguage; // Windows user-specific language } lang = lang.substr(0, 2); }Source: http://stackoverflow.com/questions/10642737/detecting-and-applying-current-system-language-on-html-5-app-on-android and http://stackoverflow.com/questions/3894488/is-there-anyway-to-detect-os-language-using-javascript |
| ||
XNA / WP7:using System.Globalization; // ... string lang = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;Source: http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.currentculture(v=vs.110).aspx |
| ||
For Linux you would import locale.h and if using C would callsetlocale(LC_ALL,"");and read the environment variable with setlocale(LC_CTYPE, NULL)Or the C++ way by creating an instance. locale lang("")and get the locale with name method lang.name() |