简体   繁体   中英

How can I get the current device language on iOS/Android?

I need to know what language is used on a iOS/Android device because I build a MonoGame application in Xamarin Studio that supports three different languages. If the current language of the device is english, than the app will show texts in english, but if the current language of the device is french, than the texts will get displayed in french instead of english. If the current language of the device is not supported in my application(for example chinese), than the default language for the texts will be english.

How can I get the current device language on iOS/Android in Xamarin Studio?

To get the language programmatically, on Android you can use:

Locale.Default.GetDisplayLanguage(Locale.Default)

On iOS :

var userLang = NSLocale.CurrentLocale.LocaleIdentifier;

You could use CultureInfo:

CultureInfo.CurrentCulture.TwoLetterISOLanguageName

Plus is cross-platform.

1) Open settings, on the home screen, tap settings 2) Tap general, on the next screen, tap general 3) Select language and region. If you're using iOS 8 or later, scroll down and tap Language & Region 4) Tap device language, on the next screen, tap "[device] Language"

That should fix your issue. However, if this does not resolve your issue, then see here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM