Wednesday, August 3, 2011

Localization of Help Files

My application is using an html file in the asset folder as a help page. Unfortunately there is no direct support from the Android system to load assets based on locale. An easy and elegant workaround is to use a R.String value for the file name:

String helpFile = getString(R.string.help_html);
String url = "file:///android_asset/" + helpFile;

Then create html files for all the supported languages and name them, e.g., de_help.htm, es_help.html. Create the appropriate language folders in res, e.g., values-de, values-es and create string.xml files with the appropriate entries for the help files,e.g.:

<string name="help_html">de_help.html</string>

At this point you probably also want to translate the rest of the strings in your application.

No comments:

Post a Comment