Localized assets in Android

I just found a good tutorial to help me implement a light user manual system in my application, as I can draw it using any plain old HTML editor.

My question is simple: since all res

ources are localizable, I can easily translate my application to new languages. What about assets

? Is there an automatic localization mechanism? I do not think so.

How do I get the system locale to generate a localized url when loading the HTML man page? Is there any call to get the size and density of the display similar to that encoded in the resource world (ie public String getDensity()

returns "xhdpi", "ldpi" ...)?

Danke; -)


source to share

4 answers

If you really need to check the current system locale, one easy way to do this is to add an id string to your strings.xml files.

For example, in the values ​​of /strings.xml add:

<string name="lang">en</string>


in values-es / strings.xml, add:

<string name="lang">es</string>


in values-fr / strings.xml add:

<string name="lang">fr</string>


etc. Then you should be able to test the programming language at the moment with something like this (to improve this of course):

if( "es".equals( getString(R.string.lang) ) ) {


Hope this helps you.



See reference for android.view.Display ( reference ) class and java.util.Locale ( reference ) class



Check out the answer here , especially pay attention to the comment.



This is an old question, but just in case someone does it. I don't think you need the extra language line as suggested above:

<string name="lang">fr</string>


Just add the resource url string and translate it:

<string name="content_location">file:///android_asset/en/index.html</string>


in values-fr / strings.xml add:

<string name="content_location">file:///android_asset/fr/index.html</string>


and then in code get it like:

String URL = getResources().getString(R.string.content_location);


and that should render the url based on local as you defined it in certain localized strings files.



All Articles