I'm doing a project where there's a search feature, but only enabled if the labels searched for are translated in the device's language. Is there any way to check if a resource exist in a specific locale? I want to avoid hard coding which translations are available.
Asked
Active
Viewed 930 times
4
-
Good question. Found here a ugly workaround https://stackoverflow.com/questions/17771531/android-how-to-get-string-in-specific-locale-without-changing-the-current-local/41907754 – Link182 Mar 31 '18 at 20:07
-
@Link182 No I actually thought of it, but the problem is that when there is no translation for a locale, the default value is still returned, it never returns null. – Nicolas Mar 31 '18 at 20:41
-
1Ok, lets assume we get a default value instead of the localized one... here we can do a additional check of equality between that value and the value from default locale, if true then localized resource is missing. – Link182 Mar 31 '18 at 21:16
-
@Link182 Doesn't work with the default language, in this case English that has no localized resource but still exist. I guess if that's the only solution I would still prefer hard coding the languages. – Nicolas Apr 01 '18 at 01:55