UIWebview加载不同文件切换语言 [英] UIWebview load different files switch langage

查看:65
本文介绍了UIWebview加载不同文件切换语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用不同的语言嵌入了HTML文件.
我想根据当前的语言在网络视图中加载正确的文件.
有没有办法像NSLocalizableString一样容易做到这一点?

I have differents embedded HTML files in different languages.
I'd like to load the correct files in a webview based on the current langage.
Is there a way to do that as easily as NSLocalizableString?

谢谢

推荐答案

例如,如果您使用本地化资源"

If you use "localized resources", for example

  • "en.lproj/index.html"中"index.html"的英语版本,
  • "fr.lproj/index.html"中的"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"];

要在Xcode中创建本地化的资源"index.html":

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

  • 在项目的信息"标签的本地化"部分中添加所需的语言(如果尚未完成的话).
  • 选择"index.html",然后在文件检查器中单击进行本地化".
  • 在文件检查器中选择所需的语言.

现在,每种语言都有一个文件,例如"index.html(英语)"和"index.html(法语)",它们在安装应用程序时会复制到相应的文件夹中.

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.

这篇关于UIWebview加载不同文件切换语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆