0

I was trying to clean some warnings in my Android Eclipse project and I came across the one complaining on the implicit locale. I understand how to fix the warning but thinking about it I realized that if I develop an Android app with English as default language and the user selects another language that my app is not providing translation for then having something like

str = getString(R.string.myString);
Locale userLocale = Locale.getDefault();
str.toLowerCase(userLocale);

may not work properly as the locale may not match the current language for str, that would be in English. In addition, I cannot assume str will be always in English if I have more languages implemented adding the file values-XX/string.xml (where XX is the contraction of other languages: "de" for German, "es" for Spanish...).

Then in order to fix this properly I would like to know if there is any way to know in which locale/language is the string that I am retrieving on calling Resources.getString() and not the locale selected by the user (that can be retrieved by Locale.getDefault()).

Community
  • 1
  • 1
Charlie
  • 152
  • 1
  • 12
  • Provide your default language (Englisch) as `values/string.xml` (without language quantifier) and Android will fall back on those in case no localisation is available. – Lukas Knuth Feb 22 '13 at 18:51
  • Hi Lukas, thanks for your answer but I think you misunderstood my question. I already know the default language should be in the values/string.xml file. So in the given example I am supposing English is already in values/string.xml and not in values-en/string.xml as it is the default language. The problem is that if I am providing other languages (imagine values-es/string.xml for Spanish) now the string coming from getString() can be either in English or Spanish, then how can I get the Locale is applying to the string I am retrieving from getString()? This is my main concern. – Charlie Feb 24 '13 at 11:46
  • Android will always try to load the values for the current locale, if present. Then, it will fall back. So if the phone is spanish, it will give you the spanish strings. It's all [here](http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch) – Lukas Knuth Feb 24 '13 at 12:09

0 Answers0