Xcode 本地化:所有字符串均未翻译

发布于 2025-01-07 23:45:08 字数 701 浏览 1 评论 0原文

我有一个 iPhone 应用程序,我想要本地化,所以我添加了中文本地化。为此,我将 Localized.strings(chinese) 添加到我的应用程序中,并在其中添加了字符串。

但是当我编译时发生了一件奇怪的事情,只有一半甚至更少的字符串被翻译。我已经尝试了一切我能做的:

  • 重新创建我的字符串文件,
  • 更改键,

甚至将工作字符串和文件放入其中。键在不起作用的字符串中,但没有任何作用。

我的所有元素都是 UILabels,并且我已经检查了每个元素的每一个配置。它们都具有相同的配置。这可能是因为项目配置的原因,但为什么有些可以工作呢?我检查了其他一些答案并尝试了解决方案(检查我的密钥、文件名等),但没有任何效果。请帮助我理解为什么会发生这种情况。

编辑: 这是我打印字符串的方法

//this one doesn't work
self.resolution.text = NSLocalizedString(@"RESOLUTION", nil);
//this one works
self.label1.text=NSLocalizedString(@"CAMERAS", nil);

在我的 Localized.strings 文件中

"RESOLUTION"="Resolution";
"CAMERAS"="Cameras";

I've an iPhone app that i wanted to localize so i've added chinese localization. To do so I added Localizable.strings(chinese) to my app and i added the strings in it.

But a weird thing happens when I compile, only half or maybe even less of the strings are translated. I've tried everything i could:

  • recreating my strings file,
  • changing keys,

even putting working string & keys in not-working string but nothing is working.

All of my elements are UILabels and I've checked every single configuration for each of them. They all have the same configurations. It can be because of the project configuration but then why does some work? I have checked some other answers and tried the solutions (checking my keys, file name etc) but nothing is working. Please help me understand why is it happening.

EDIT:
Here's how I print my strings

//this one doesn't work
self.resolution.text = NSLocalizedString(@"RESOLUTION", nil);
//this one works
self.label1.text=NSLocalizedString(@"CAMERAS", nil);

And in my Localizable.strings file i have

"RESOLUTION"="Resolution";
"CAMERAS"="Cameras";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

沙与沫 2025-01-14 23:45:08

进行另一项检查,例如反转元素的顺序:尝试将无法翻译的字符串放在顶部。然后作为概念证明,尝试使用非 utf-8 字符制作第三个本地化文件(就像没有多余装饰的纯文本)

make another check, like inverting the order of the elements: try putting on the top on of the strings that does not figure out translated. then as a proof of concept try making a third localized file with non utf-8 chars (like in plain text with no frills)

情话墙 2025-01-14 23:45:08

我的问题的解决方案是从模拟器中删除应用程序并重新构建,如 holographix 所解释的。谢谢holographix:)

我仍然不明白的是,我多次尝试了该程序,但它不起作用,然后就像它决定开始工作一样。尽管我的问题已经解决,但对我来说仍然是个谜。

The soltuion to my problem was to delete app from simulator clean and build again as explained by holographix. Thanks holographix :)

What i still don't understand is that i tried the procedure many times and it didn't work and then just like that it decided to start working. Even though my problem is solved it's still a mystery to me.

中性美 2025-01-14 23:45:08

带着 Xcode 7 回归。还有一个技巧。

我遇到了同样的问题,但上述解决方案都不起作用(我并不是说它在其他情况下不起作用)。

解决方案是我在一个定义的末尾有一个双 ; (可能是由于某些剪切、复制、粘贴操作)。没有编译错误或警告。我只是删除了多余的;这又起作用了。

Coming back with Xcode 7. With one more trick.

I had the same problem but none of the above solutions did work (I'm not saying that it wouldn't work in other situations).

The solution was that I have a double ; at the end of one definition (probably due to some cut,copy,paste operation). There was no compilation error or warning. I simply removed the redundant ; and that worked again.

咋地 2025-01-14 23:45:08

我有类似的问题。就我而言,这是因为从 Google 翻译复制翻译后,*.strings 文件中的语音标记是不同的字符代码。
重新输入语音标记修复了它。

I had the similar issue. In my case, it was because the speech marks were different character codes in the *.strings file after copying the translation from Google translate.
Reentering the speech marks fixed it.

笑梦风尘 2025-01-14 23:45:08

将您的 .strings 文件名更改为 Localized.strings,它对我有用。

Change your .strings file name to Localizable.strings, it worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文