Android : assets dir and multi language

 ̄綄美尐妖づ 提交于 2019-12-25 05:14:54

问题


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 language but when I start the application it always display the file into assets directory also if the device language is set to italian. Why ?


回答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.




回答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.



来源:https://stackoverflow.com/questions/10088141/android-assets-dir-and-multi-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!