Skip to content Skip to sidebar Skip to footer

Android : Assets Dir And Multi Language

Good morning. Into my android application I have in assets directory a file changelog. I have creato also the directory assets-it and I have put into the file changelog in italian

Solution 1:

That is the expected behavior. Resources in res/ can be localized in that manner, but the assets/ directory cannot.

Since it's just a changelog, I'd recommend storing it as a localized string resource in res/values-LOCALE/. If you really want localization of assets, you could manually recreate it by getting the current locale and loading, e.g. assets/changelog-en, vs. assets/changelog-it, but I think that would generally not be a good idea, and it certainly isn't necessary in your case.

Solution 2:

Try this:

  1. put both changelog files into assets folder:

Path is for example: assets/en/changelog_file and assets/it/changelog_file

  1. enter this into your values/strings.xml:

<string name="changelog_file">file:///android_asset/en/changelog_file</string>

  1. put in your values-it/strings.xml:

<string name="changelog_file">file:///android_asset/it/changelog_file</string>

Like this you can call the string from the code: getResources().getString(R.string.changelog_file) and it will call the values-en or values-it according to device locale.

Post a Comment for "Android : Assets Dir And Multi Language"