Esq*_*uth 2 nslocalizedstring swift xcode6 ios8
我无法理解并找到任何向我展示NSLocalizedString实际用途的资源.即使是Apple文档..
NSLocalizedString(<#key: String#>, tableName: <#String?#>,
bundle: <#NSBundle#>, value: <#String#>, comment: <#String#>)
Run Code Online (Sandbox Code Playgroud)
好吧,假设我在一个文件中创建了这个,我该如何为不同的语言编写这个?
我是否创建了整个文件的本地化版本,如:en.thisfile.swift,es.thisfile.swift,fr.thisfile.swift?
或者我在不同的包或表中创建新语言?
NSLocalizedString("hello", tableName: "en", value: "hello", comment: "wtf is this anyways?")
NSLocalizedString("hello", tableName: "fr", value: "bonjour", comment: "wtf is this anyways?")
NSLocalizedString("hello", tableName: "es", value: "hola", comment: "wtf is this anyways?")
Run Code Online (Sandbox Code Playgroud)
然后如何在设置后在随机文件中使用它?
println("dat nslocalizedstring I created, which will automatically know what to write??")
Run Code Online (Sandbox Code Playgroud)
Sul*_*han 11
这table
是定义字符串的文件的名称,例如,表"ErrorMessages"将定义一个名为的文件ErrorMessages.strings
.
如果未指定表,则该文件将是默认值Localizable.strings
.该文件的格式是以下列表:
/* This is displayed when the entity is not found. */
"MSG_object_not_found" = "Object not found. Please, try again.";
Run Code Online (Sandbox Code Playgroud)
如果第一行是注释,则左侧的值是key
标识字符串的值,右侧的值是实际的本地化值.
通常,您可以使用英语值作为键(2参数版本NSLocalizedString
).语言名(en
,fr
,es
)不是方法调用的一部分.
所有这些都是为了简化翻译.请注意,大多数翻译人员都不会理解甚至看不到应用程序,这就是为什么有一个好评论来为消息提供上下文的重要性.互联网上有一些有趣的翻译例子是因为语境缺失而译员不知道他们翻译的是什么.
基本上,你的代码将包含文本在你的主要语言,然后你会生成.strings
使用从您的代码文件genstring
的工具(请参阅此获取更多信息).然后,您将文件提供给翻译器,将翻译后的文件添加到应用程序(不同文件夹中的每种语言),应用程序将根据用户选择的语言在运行时选择正确的文件.
归档时间: |
|
查看次数: |
5888 次 |
最近记录: |