Reputation: 181
As we all know that we have values folder arranged depending on language selected for example value-en
, value-ja
.
I just want to check whether the specific value folder exists or not?
For example i want to check value-fr
is present or not in res
folder?
Upvotes: 3
Views: 252
Reputation: 25846
The first thing that comes to my mind is to define boolean item in values/localized.xml
(or some other resource file like strings.xml
):
<resources>
<bool name="localized">false</bool>
</resources>
Then override it in each values-xx
folder:
<resources>
<bool name="localized">true</bool>
</resources>
Now you can create Resource
object for specific locale and check localized
resource value:
Resources currentResources = getResources();
AssetManager assets = currentResources.getAssets();
DisplayMetrics metrics = currentResources.getDisplayMetrics();
Configuration config = new Configuration(currentResources.getConfiguration());
config.locale = Locale.FRENCH;
Resources localizedResources = new Resources(assets, metrics, config);
if (localizedResources.getBoolean(R.bool.localized)) {
// values-fr exists
}
Upvotes: 1