UIWebview load different files switch langage

不想你离开。 提交于 2019-12-07 15:17:35

If you use "localized resources", for example

  • english version of "index.html" in "en.lproj/index.html",
  • french version of "index.html" in "fr.lproj/index.html",

then many resource functions will automatically select the correct version (based on the user's language setting), e.g.:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];

To create a localized resource "index.html" in Xcode:

  • Add the required languages in the "Localizations" section of the "Info" tab of your project (if you have not done that already).
  • Select "index.html", and click on "Make Localized" in the File Inspector.
  • Select the required languages in the File Inspector.

Now you have one file for each language, for example "index.html (English)" and "index.html (French)", which are copied to the appropriate folder when you install the app.

If for current language you mean the phone language you could achieve your goal doing this :

NSString *locale = [[NSLocale preferredLanguages] objectAtIndex:0];

the method return a two letter string representing the current language, IT(Italian),EN(English),DE(German) etc. So based on the language you should be able to load the corresponding HTML file.

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