现在的位置: 首页 > 综合 > 正文

setting bundle 多语言,本地化,系统设置,ios

2018年05月28日 ⁄ 综合 ⁄ 共 903字 ⁄ 字号 评论关闭

【来自blog.csdn.net/lanmanck】

网上找了一堆,说的不清不楚,经过摸索,与君分享。

新建一个setting.bundle后结构如下:

Settings.bundle

--en.lproj

----Root.strings

--Root.plist

大家一般都在Root.plst里面添加删除条目,那么要本地化/国际化语言怎么办?

看目录应该是新建一个en.lproj这样的目录,例如中文的为:zh_CN.lproj。我摸索了半天,xcode是不能添加目录到Settings.bundle,要在finder里打开,靠!

在xcode里右键->Show in finder,然后再选中右键->显示包内容,这下就可以编辑了。

这时依葫芦画瓢建lproj目录即可,新的结构如下:

Settings.bundle

--en.lproj

----Root.strings

--Root.plist

--zh_CN.lproj

----Root.strings

根据不同语言,设置相应字符串,比如有个设置名称为Title,显示的是一个string类型,那这个string就是Root.strings里面的,我们可以在en.lproj/Root.strings设置为:

"Appdebugenable" = "App debug enable"

在zh_CN.lproj/Root.strings设置为:

"Appdebugenable" = "APP调试使能";

这样,在Root.plist里写入Appdebugenable即可完成本地化/国际化了!而那个identifier就是程序用来访问的id!

至于用法,就简单了,以bool为例:

读取:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

[defaults boolForKey:identifierSetEnable];

写入:

[defaults setBool:YES forKey:identifierSetEnable];

这里说的比较清楚,可参考:http://loong.blog.51cto.com/358149/930860

抱歉!评论已关闭.