What is the best way to handle internationalization/localization in an Android WebView. Ideally, I would like to access all the string resources in:
res/values/strings.xml
res/values-de/strings.xml
…
Has anybody done this in an efficient way?
Android Localization information:
http://developer.android.com/guide/topics/resources/localization.html
Best,
— Thomas Amsler
To load some localized data in a webview, I created a string containing a localized URL, and used that to load an HTML file.
So for example a string:
to reference a file
localized_ru.htmlin the/assetsdirectory, and then in the activity:I used this indirect via a string since
assets/directory is not localized, and loading a resource using a URL didn’t work for me.If you really want to be able to load all string resources from your webview, you can create a JavaScript-interface and a simple helper class:
then pass that to the webview in your activity: