localization of assets files localization of assets files android android

localization of assets files


This isn't supported directly but here is what I have done...

Separate your files into groups by country code (like what you would do for normal resource files) and then create a localized string in each of your localized string.xml files called something like "prefix" (where prefix would be "en" for English for example).

Then when you build your asset filenames simple use something like getString("prefix") + "-" + "<name-of-asset->.

At least some variation of the above should work for you.


Put your files into the assets folder with local suffix. Define a String resource 'myLocalizedFileName' for every file and get the filename via R.string.myLocalizedFileName.

Example:

Folder structure:

assets/assets/help.htmlassets/help_de.htlm

String resources for every language in res/values/strings.xml:

<resource>  <string name=helpFile>help.html</string></resource>

WebView calling:

public class HelpActivity extends AppCompatActivity {  protected void onCreate(Bundle savedInstanceState) {    ...    findViewById(R.id.helpWebView)      .loadUrl("file:///android_asset/"          + getString(R.string.helpFile));  }}


If you want to localize a HTML file you can simply put it under res/raw-<language>/filename.html (where <language>=en, es, fr, it, etc.) then access it from your code with the resource ID R.raw.filename. The framework will pick the right file according to the locale.