【问题标题】:My localized strings are not detected未检测到我的本地化字符串
【发布时间】:2011-09-07 14:45:27
【问题描述】:

我正在尝试在 Xcode 4 中本地化我的字符串,但我得到的唯一东西是键,而不是值。

我已经使用NSLocalizedString(key, comment) 本地化了字符串。 我已经使用命令行中的 genstrings 生成了文件 Localizable.strings 。 我已将 Localizable.strings 从 Finder 拖放到 Xcode(到 Resources 文件夹中)。 我已本地化 Localizable.strings 并添加了相应的国家/地区。 我已经确定编码是 UTF-16。 我已经为每个国家/地区翻译了不同的 Localizable.strings。 我重新检查了编码仍然是 UTF-16。 我检查了 Localizable.strings 中的每个语句都以分号结尾。

还是不行。

知道我错过了什么吗?

编辑

这是我的 Localizable.strings 的一部分

/* Text displayed on the comment button if there are more than one comment. */
"CommentButtonTextPlural" = "comments";

/* Text displayed on the comment button if there is exacly one comment. */
"CommentButtonTextSingular" = "comment";

/* Text displayed on the post button. */
"CommentViewPostButtonLabel" = "Post";

/* Default text displayed in the area where the user types in a comment. */
"CommentViewWriteAComment" = "Write a comment...";

/* Error message explaining that a document isn't viewable on the user's device. */
"DocumentRendererStatusDetailedErrorText" = "This document is not viewable on this device.";

/* Message explaining that the document is downloading. */
"DocumentRendererStatusDownloadingText" = "Downloading...";

【问题讨论】:

  • 你能发布你的 Localizable.strings 的内容吗?如果不是全部,至少是标题和前几个键。
  • 完成。我在文件的一部分中添加了英文翻译(呃!)。 :-)

标签: objective-c ios xcode4


【解决方案1】:

您可能将 Localizable.strings 文件放在了错误的位置,因此它使用了默认翻译。

当您添加新语言时,Xcode 会在您的 App Directory 中创建一个以 .lproj 结尾的新文件夹(因此对于英语,它将是 en.lproj),这就是您的英语 Localizable.strings 文件应该所在的位置。

如果你想要法语,添加法语,Xcode 会生成一个 fr.lproj 目录,这就是法语 Localizable.strings 文件所在的位置。

根据您的描述,将其放在资源文件夹中是不正确的。

【讨论】:

  • 我在 Resources 中添加了原始的 Localizable.strings(在 Xcode 中)。当我本地化文件时,Xcode 会创建 xx.lproj 文件夹并在每个文件夹中放置一个 Localizable.strings 的副本。对于我计划支持的七种语言中的每一种,我都有一个 xx.lproj 文件夹(每个文件夹中都有一个 .strings 文件)。
【解决方案2】:

您的本地化应如下所示:

在您的桌面上:

【讨论】:

  • Xcode4 从来没有为我创建 App Resources 文件夹,也没有创建 Localization 文件夹。但是我创建了文件夹并相应地移动了 Localizable.strings 。不过还是不行。
  • 这是我创建的一个组,您至少应该拥有 Localization 组,尽管带有 Localizable.strings。
  • 如果你的项目看起来和我的截图类似,并且你正确使用了NSLocalizedString,那么它应该可以正常工作。
  • 谢谢,现在已经成功了。但是,它似乎不需要本地化组才能工作。当我本地化 Localization.string 时,Xcode 也没有创​​建它。
  • Localizable.strings 是必需的。
【解决方案3】:

我设法让它工作了。

我所做的是删除了 genstrings 为我创建的 Localizable.strings(从硬盘驱动器中,我没有触及位于 xx.lproj 文件夹中的文件)文件,并删除了我设备上的应用程序文件。

【讨论】:

  • +1 用于从设备中删除应用程序并重新安装。在我这样做之前,我的应用程序没有使用本地化字符串。
猜你喜欢
  • 2014-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-11
  • 2019-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多