- Home /
Using Application.systemLanguage returns Unknown
On Android if I get the string of .systemLanguage while my phone is set to German it returns unknown. Is there some other way to get the language? Or is there some issue with Unity?
I'm feeling it is something with Unity as I am partly sure I have had my localisation swapping dependant on what language my phone was set to.
If it is just broken in Unity how else can I get the devices language?
Edit: I'm using the Nexus 4 (Android 4.3) with Unity 4.3.0f4
Here is way to get actual data for debuggin or for searching your localizations: string localization = Application.systemLanguage.ToString();
Answer by Bunny83 · Jun 18, 2014 at 11:57 AM
Well, just tried it on my Nexus7 and it worked well. However i still use Unity 4.3.4f1 but i'm just downloading Unity 4.5.1 as i write this ;)
Keep in mind that systemLanguage isn't a string! It's a enum. However if you "concat" a string with an enum value it will be converted to a string:
GUILayout.Label("systemLanguage :"+Application.systemLanguage);
This prints "systemLanguage :German" for me. I usually have set the language to English and it also prints correctly if i set the language to English.
edit
Just installed Unity 4.5.1f3 and it still works for me just fine. You might want to try my MobileStats app (just made a fresh build) and see if it works for you. I added the system language as the last point in the general info box.
second edit
I just wrote two helper functions which uses the JNI interface to query the system language directly from the JAVA environment:
// C#
// returns "en" / "de" / ...
public static string GetLanguage()
{
#if UNITY_ANDROID
try
{
var locale = new AndroidJavaClass("java.util.Locale");
var localeInst = locale.CallStatic<AndroidJavaObject>("getDefault");
var name = localeInst.Call<string>("getLanguage");
return name;
}
catch(System.Exception e)
{
return "Error";
}
#else
return "Not supported";
#endif
}
// returns "eng" / "deu" / ...
public static string GetISO3Language()
{
#if UNITY_ANDROID
try
{
var locale = new AndroidJavaClass("java.util.Locale");
var localeInst = locale.CallStatic<AndroidJavaObject>("getDefault");
var name = localeInst.Call<string>("getISO3Language");
return name;
}
catch(System.Exception e)
{
return "Error";
}
#else
return "Not supported";
#endif
}
The point of the question is that the value is SystemLanguage.Unkown ins$$anonymous$$d of SystemLanguage.German Why is Unity not able to detect the language?
And my answer clearly said that it does work. If it doesn't work on your device it's most likely something with your device. You didn't even tell us what device you're using and what Android version.
Do you have any security addons or a custom Android version? Have you tried my test app? Does it also say $$anonymous$$?
ps: you should never do a language selection only based on what's the system's language. You should always provide an in game menu to select a language. You can use Application.systemLanguage to do a preselection but forcing it to the system language is always a bad idea.
I always have my system language set to english, however i'm german as well.
You can always use a native plugin or use JNI to query values from the Android SD$$anonymous$$ such as the system language. I'll add an example to my answer.
ps: I've updated my test app which now includes the 2 and 3 character language code returned by getLanguage and getISO3Language
Thanks for the updated answer. I'm using the Nexus 4 (Android 4.3) to test this. Other (non unity) apps were switching happily when the system was in German mode. I'm using AppLock as a security add on. Does that affect Unity's ability to detect language? The example code gave "de" and "deu" respectively. Either way I'll use the method in the Stackoverflow answer.
Thanks for the response (even with my lack of details!)
Oh and there will indeed be a button to choose language!
Thank you! You saved my day! There are no Farsi (Persian, "fa") and Tagalog (Filipino, "tl") in Application.systemLanguage so the only way to detect those languages was to use native code for the case when Application.systemLanguage equals to SystemLanguage.Unknown.
Your answer

Follow this Question
Related Questions
What is Mono? Is it a compiler? A language? Or what? 3 Answers
adding localization 1 Answer
how to transfer data to unity efficiently 1 Answer
Embedding scripting language (webgl-compatible) 3 Answers
Unity2019.3 and I18N.dll 1 Answer