【问题标题】:What is the second parameter of NSLocalizedString()?Swift 中的 NSLocalizedString 注释参数
【发布时间】:2017-10-15 09:07:21
【问题描述】:

据我在 Apple Developer 网站上阅读有关 NSLocalizedString 的信息:https://developer.apple.com/reference/foundation/nslocalizedstring

NSLocalizedString 初始化程序中的注释参数应执行以下操作,如 Apple 开发文档“放置在字符串文件中键值对上方的注释”中所述。

所以我假设使用以下代码:

label.text = NSLocalizedString("HELLO_WORLD", comment: "Text for greeting label.")

将更新我的 Localizable.strings 文件中的相应字符串,但所有文件都不会更改,其中的所有内容都是:

"HELLO_WORLD" = "你好,世界!";

不确定我是否走在正确的道路上,或者我是否误解了评论论点的目的。

【问题讨论】:

    标签: ios xcode swift3 localization


    【解决方案1】:

    根据Localizing Your App documentation,您可以为本地化团队导出本地化。您放入NSLocalizedString 的cmets 包含在导出的文件中。

    导出本地化会创建带有xliff 扩展名的文件,其中包含类似于下面代码的 XML。

    <trans-unit id="Settings">
        <source>Settings</source>
        <target>설정</target>
        <note>Label of the button to Settings screen</note>
    </trans-unit>
    <trans-unit id="Take Photo">
        <source>Take Photo</source>
        <target>사진 찍기</target>
        <note>No comment provided by engineer.</note>
    </trans-unit>
    

    XLIFF 文件可以使用XLIFFTool 等应用本地化工具进行编辑。

    【讨论】:

      【解决方案2】:

      comment 参数用于方便翻译。它与 NSLocalizedString 函数的输出无关。它只会帮助翻译者翻译其他内容。

      【讨论】:

      • 感谢您的回答,我知道注释参数不会影响 NSLocalizedString 返回的字符串。文档声明注释参数中的字符串位于字符串文件中的键值对之上,这没有发生。我想知道我是否误解了文档,或者如果没有,为什么评论没有出现在我的 Localizable.strings 文件中。
      • 不,除非您手动将其放在那里,否则它不会出现,这就是我所说的注释不会出现在字符串文件上,它只是为了翻译者的利益。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-26
      • 1970-01-01
      • 2019-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多