0

Is there a solution for xamarin-ios to get the current culture in the format like (en_US, de_CH, ..)? I read so many articles in the web and here on stackoverflow. But I can't find a nice solution for this.

Following code snippet returns not this format everytime. Sometimes I get "gsw_DE" and so on (ISO 639-2 instead of 639-1)

NSLocale.CurrentLocale.Identifier;

My current solution is to do it by myself:

var languagecode = NSLocale.PreferredLanguages[0];

var result = String.Format("{0}_{1}", languagecode.Substring(0, 2), NSLocale.CurrentLocale.CountryCode);

Above workaround is from: Get iOS current language (including country code)

I need to make sure that I get the value in this format. Is there another way? Thanks

Community
  • 1
  • 1
Joehl
  • 3,671
  • 3
  • 25
  • 53

1 Answers1

0

We are still in the C# world, aren't we? You can use CultureInfo.CurrentUICulture.Name and it'll give you "en-US" for "default" English and "en-GB" for English UK. Language settings are in General - Language & Region - iPhone Language.

Artur Shamsutdinov
  • 3,127
  • 3
  • 21
  • 39
  • Yes. That's what I tried at first. But on one of our iOS devices, the value is everytime not set (empty string). Even if I change the language on the phone. Some web searchs result in the key, that this is the wrong way to get the current culture/language for ios. – Joehl Jun 17 '15 at 14:11
  • Do you have issues with some particular languages? As I've tested CultureInfo.CurrentUICulture on my phone and it works just fine. Which Xamarin version are you using? – Artur Shamsutdinov Jun 18 '15 at 00:09
  • I think the problem is the language itselfs. The phone supports swiss-german-language. And this is not an ISO 639-1 standard. In case of this, the CultureInfo.CUrrentUICulture is not set. The other iPhon-devices which are not swiss-german worked. – Joehl Jun 18 '15 at 07:11