简体   繁体   English

无法从 Localizable.strings 文件中检索本地化的字符串

[英]Can't retrieve localized strings from Localizable.strings file

I'm unable to get the correct localized german strings from the Localizable.strings file.我无法从 Localizable.strings 文件中获取正确的本地化德语字符串。 My app setup looks like this我的应用程序设置如下所示

  • Main.storyboard主故事板

    • Main.storyboard (Base) Main.storyboard(基础)
    • Main.strings (German) -> these strings are translated correctly Main.strings (German) -> 这些字符串被正确翻译
  • Localizable.strings可本地化的字符串

    • Localizable.strings (English) Localizable.strings(英文)
    • Localizable.strings (German) -> can't get these strings Localizable.strings (German) -> 无法得到这些字符串

Inside the app I'm trying to get the string like this在应用程序中,我试图获取这样的字符串

NSString *item = NSLocalizedString(@"Group expenses", @"Menu item");

The Localizable.strings (German) file looks like this Localizable.strings(德语)文件如下所示

/* Menu item */
"Group expenses" = "Gruppenausgaben";

When I set a breakpoint after item I always get the English string back, however the path for the resource seems correct NSString *path = [[NSBundle mainBundle] pathForResource:[[NSLocale preferredLanguages] objectAtIndex:0] ofType:@"lproj"];当我在item之后设置断点时,我总是得到英文字符串,但是资源的路径似乎是正确的NSString *path = [[NSBundle mainBundle] pathForResource:[[NSLocale preferredLanguages] objectAtIndex:0] ofType:@"lproj"]; gives me: /data/Containers/Bundle/Application/5E3ED6BF-71E1-4C60-9EDA-610C9A32B8EF/MyApp.app/de.lproj给我: /data/Containers/Bundle/Application/5E3ED6BF-71E1-4C60-9EDA-610C9A32B8EF/MyApp.app/de.lproj

I also have localized the string file我也本地化了字符串文件

在此处输入图片说明

在此处输入图片说明

It's also included in Copy Bundle Resources它也包含在复制捆绑资源中

在此处输入图片说明

I tried several answers from different questions here on stackoverflow, like deleting app and do a clean (shift+cmd+k), setting application language under Edit Scheme , ...我在 stackoverflow 上尝试了来自不同问题的几个答案,例如删除应用程序并进行清理(shift+cmd+k),在Edit Scheme下设置应用程序语言,...

Ok, I think I know the reason for your bug.好的,我想我知道你的错误的原因。 Parse had an issue with adding Localizable.strings as documented here . Parse 在添加 Localizable.strings 时遇到问题,如此处所述 This was fixed in 1.8.1 version of their framework:这在他们框架的 1.8.1 版本中得到了修复:

V1.8.1 — AUGUST 19, 2015 V1.8.1 — 2015 年 8 月 19 日

... ...

Fixed: Overwritten localizations when used via CocoaPods and integrating as static library.修复:通过 CocoaPods 使用并作为静态库集成时覆盖本地化。

... ...

You can also check this question.你也可以检查这个问题。

So, just make sure you use the latest version of the framework and all should work :)所以,只要确保你使用最新版本的框架,一切都应该可以工作:)

I encountered a same problem before, some approach you can try:我之前遇到过同样的问题,您可以尝试一些方法:

  • Make sure you set German as your iOS device system language.确保将德语设置为 iOS 设备系统语言。

  • Run this app in Xcode, then stop.在 Xcode 中运行这个应用程序,然后停止。 Launch the app from the iOS device manually.从 iOS 设备手动启动应用程序。 (First launch with Xcode will use base language, I don't know why) (首次使用 Xcode 启动将使用基本语言,我不知道为什么)

  • See if it works看看它是否有效

Just had a similar issue was cracking my head, do a search of the xx.strings file I had an old copy of the bloody file messing me up.刚刚有一个类似的问题让我头疼,搜索 xx.strings 文件我有一个血腥文件的旧副本把我搞砸了。

find ./ -name "xx.strings" -print

double check your string file is proper仔细检查您的字符串文件是否正确

plutil -lint  xx.strings

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM