how does the if condition look like?
if(Locale.getDefault().equals("English")){
Log.i("Language","Englisch");
} else if(Locale.getDefault().equals("Deutsch")){
Log.i("Language","Deutsch");
}
This won't work
how does the if condition look like?
if(Locale.getDefault().equals("English")){
Log.i("Language","Englisch");
} else if(Locale.getDefault().equals("Deutsch")){
Log.i("Language","Deutsch");
}
This won't work
Locale.getDefault()
will return a static
Locale
Object, not a String
. So calling Locale.getDefault().equals("English")
will not work.
Try this:
String language = Locale.getDefault().getLanguage();
if (language.equals("en"))
{
// Use English link
}
else if (language.equals("de"))
{
// Use German link
}
public String getLanguage ()
Added in API level 1
Returns the language code for this Locale or the empty string if no language was set.
Or:
String language = Locale.getDefault().getDisplayLanguage();
if (language.equals("English"))
{
// Use English link
}
else if (...) { ....
public final String getDisplayLanguage ()
Added in API level 1 Equivalent to
getDisplayLanguage(Locale.getDefault()).
Here are other possibilities:
Locale.getDefault().getLanguage() ---> en
Locale.getDefault().getISO3Language() ---> eng
Locale.getDefault().getCountry() ---> US
Locale.getDefault().getISO3Country() ---> USA
Locale.getDefault().getDisplayCountry() ---> United States
Locale.getDefault().getDisplayName() ---> English (United States)
Locale.getDefault().toString() ---> en_US
Locale.getDefault().getDisplayLanguage()---> English
Documentation here.
Locale.getDefault
returns a Locale
, not a String
. If you want to know more about that locale you call getLanguage
and getCountry
on the Locale
. Look up ISO code for language and country.res/values-en/
and res/values-de/
you can define language specific strings.