How to get iOS device system language?

1,287 views
Skip to first unread message

4ila...@gmail.com

unread,
Apr 2, 2014, 9:52:59 AM4/2/14
to rob...@googlegroups.com
Is there workable way to get proper system language?

Now I use java.util.Locale.getDefault().toString() 

But the problem is that when I set Russian language as system language on iPhone like this


java.util.Locale.getDefault().toString() returns me "en_US" not "ru_RU" as it should.

Tiarsoft

unread,
Apr 3, 2014, 12:29:22 AM4/3/14
to rob...@googlegroups.com
I do it this way -> 

Locale.getDefault().getLanguage();

for spanish it returns "es"

Jon Renner

unread,
Apr 3, 2014, 1:13:09 AM4/3/14
to rob...@googlegroups.com
When I did language testing I had to not only change language in settings but also change region or it would show up as en_US

4ila...@gmail.com

unread,
Apr 3, 2014, 3:03:19 AM4/3/14
to rob...@googlegroups.com
Yes, you are right. Locale.getDefault().getLanguage(); dealing with device region not device language.


May be there is still some way to take language not region as a condition?


четверг, 3 апреля 2014 г., 8:13:09 UTC+3 пользователь Jon Renner написал:

Niklas Therning

unread,
Apr 7, 2014, 4:38:46 PM4/7/14
to 4ila...@gmail.com, rob...@googlegroups.com
You may want to have a look at the NSLocale class if you need more info than java.util.Locale provides.


--
You received this message because you are subscribed to the Google Groups "RoboVM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robovm+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nick Susha

unread,
Apr 8, 2014, 8:47:41 AM4/8/14
to rob...@googlegroups.com, 4ila...@gmail.com

This line of code

new NSLocale(); 

throws an Exception

Exception in thread "main" java.lang.RuntimeException: Objective-C initialization method returned nil

at org.robovm.objc.ObjCObject.initObject(ObjCObject.java)

at org.robovm.apple.foundation.NSObject.<init>(NSObject.java)

at org.robovm.apple.foundation.NSLocale.<init>(NSLocale.java)

at com.forilab.voodoo.VoodooIOS.getSystemLanguage(VoodooIOS.java)

at com.forilab.voodoo.utils.LanguagesManager.<init>(LanguagesManager.java)

at com.forilab.voodoo.utils.LanguagesManager.getInstance(LanguagesManager.java)

at com.forilab.voodoo.screens.SettingsScreen.<init>(SettingsScreen.java)

at com.forilab.voodoo.VoodooGame.init(VoodooGame.java)

at com.forilab.voodoo.screens.SplashScreen.render(SplashScreen.java)

at com.badlogic.gdx.Game.render(Game.java)

at com.badlogic.gdx.backends.iosrobovm.IOSGraphics.draw(IOSGraphics.java)

at com.badlogic.gdx.backends.iosrobovm.IOSGraphics$1.draw(IOSGraphics.java)

at org.robovm.apple.uikit.UIView.$cb$drawRect$(UIView.java)

at org.robovm.apple.glkit.GLKView.$m$super$display(Native Method)

at org.robovm.apple.glkit.GLKView.display(GLKView.java)

at org.robovm.apple.glkit.GLKView.$cb$display(GLKView.java)

at org.robovm.apple.uikit.UIApplication.main(Native Method)

at org.robovm.apple.uikit.UIApplication.main(UIApplication.java)

at com.forilab.voodoo.VoodooIOS.main(VoodooIOS.java)

Niklas Therning

unread,
Apr 8, 2014, 9:34:08 AM4/8/14
to Nick Susha, rob...@googlegroups.com, 4ila...@gmail.com
Oh, ok the default constructor in NSLocale should be removed. Please try with the constructor that takes a Locale or the one which takes a String. Or one of the static methods which return the current locale.
--

Nick Susha

unread,
Apr 14, 2014, 4:56:45 AM4/14/14
to rob...@googlegroups.com, Nick Susha, 4ila...@gmail.com

Unfortunately, I still have the problems

NSLocale.getSystemLocale().toLocale() constantly throws an Exception

java.lang.IllegalArgumentException: Failed to convert NSLocale <__NSCFLocale: 0x10649eb0> to Java Locale

NSLocale.getCurrentLocale().toLocale().toString() returns "en_GB" even if I set device language to Russian like this

Niklas Therning

unread,
Apr 14, 2014, 5:08:01 AM4/14/14
to Nick Susha, rob...@googlegroups.com, 4ila...@gmail.com
What does NSLocale.getSystemLocale().getLocaleIdentifier() return? There could be a bug in the toLocale() method. I haven't tested it.


--

Nick Susha

unread,
Apr 14, 2014, 8:44:09 AM4/14/14
to rob...@googlegroups.com, Nick Susha, 4ila...@gmail.com
out.println("NSLocale.getSystemLocale().getLocaleIdentifier() = \""+NSLocale.getSystemLocale().getLocaleIdentifier()+"\"");

produces following output

NSLocale.getSystemLocale().getLocaleIdentifier() = ""

Dmitry Kolesnikovich

unread,
Apr 18, 2014, 2:50:09 AM4/18/14
to rob...@googlegroups.com, Nick Susha, 4ila...@gmail.com
May be some one have this issue and already found the solution?

Torsten Kunkel

unread,
Apr 18, 2014, 9:02:17 AM4/18/14
to rob...@googlegroups.com
I hope it helps,


import org.robovm.apple.foundation.NSUserDefaults;

org.robovm.apple.foundation.NSArray<?> lang = NSUserDefaults.standardUserDefaults().arrayForKey$("AppleLanguages");

System.out.println(lang);
System.out.println(lang.getFirst());

These values change, depending on the language I choose in the settings of the device.

Dmitry Kolesnikovich

unread,
Apr 19, 2014, 5:34:58 AM4/19/14
to rob...@googlegroups.com
Thanks, it works.

PS.

NSUserDefaults.standardUserDefaults().arrayForKey$("AppleLanguages").getFirst().toString();

returns"ru" for Russian, "en" for English, "fr" for French, etc

Dmitry Kolesnikovich

unread,
Apr 19, 2014, 5:59:36 AM4/19/14
to rob...@googlegroups.com
The only issue I face iOS 6 is that when I change language it still returns me previous language even if I relaunch the app.
Reply all
Reply to author
Forward
0 new messages