Xcode 5/iOS 7 - 本地化在模拟器中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19058499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:47:37  来源:igfitidea点击:

Xcode 5/iOS 7 - localization not working in simulator

iosxcodeios7localizationios-simulator

提问by PruitIgoe

I was following one of Ray Wenderlich's tutorials on localization but I can't seem to get it working.

我正在关注 Ray Wenderlich 关于本地化的教程之一,但我似乎无法让它工作。

I've set my project up for localization in English and French and I have a locaziable.strings file for each:

我已经将我的项目设置为以英语和法语进行本地化,并且每个项目都有一个 locaziable.strings 文件:

enter image description here

在此处输入图片说明

The French file has the correct (well as far as Google translate goes) French versions of my string:

法语文件具有正确的(就谷歌翻译而言)我的字符串的法语版本:

enter image description here

在此处输入图片说明

I'm setting the strings by calling the correct key from the localizable.strings file:

我通过从 localizable.strings 文件中调用正确的键来设置字符串:

 NSString* strTitle = [NSString stringWithFormat:NSLocalizedString(@"Title", Nil)];

And I have the simulator set to French (BTW: Whenever I do a language change the simulator crashes).

而且我将模拟器设置为法语(顺便说一句:每当我更改语言时,模拟器就会崩溃)。

But it is not pulling from the correct localizable.strings file. It's still displaying in English:

但它不是从正确的 localizable.strings 文件中提取的。它仍然以英文显示:

enter image description here

在此处输入图片说明

Am I doing something wrong?

难道我做错了什么?

采纳答案by Theo

Maybe you have run the app at some time where the file Localizable.stringsalready existed but has not been localized yet. If this is the case, this unlocalized file still resides in the resources folder in the application bundle in the simulator (when you build an run a new version of your app in the simulator or in the device, unused files will not be deleted). This can lead to problems.

也许您在文件Localizable.strings已经存在但尚未本地化的某个时间运行了该应用程序。如果是这种情况,这个未本地化的文件仍驻留在模拟器中应用程序包的资源文件夹中(当您在模拟器或设备中构建运行新版本的应用程序时,不会删除未使用的文件)。这可能会导致问题。

Try to delete the app completely from the simulator and build an run again.

尝试从模拟器中完全删除应用程序并再次构建运行。

回答by Rajal

If you are using xcode 6.1.1 and iOS sdk 8.1,try this workaround.

如果您使用的是 xcode 6.1.1 和 iOS sdk 8.1,请尝试此解决方法。

It seems localization does not work with xCode 6.1 and 8.1 simulator. Workaround: Go to "edit schemes" >> "Run" (side bar) >> "Options" tab >> "Application Language" Select the language you wish to run the app on the simulator. I got this workaround from Workaroundby natanavraThanks to him.

本地化似乎不适用于 xCode 6.1 和 8.1 模拟器。解决方法:转到“编辑方案”>>“运行”(侧栏)>>“选项”选项卡>>“应用程序语言”选择您希望在模拟器上运行应用程序的语言。我从这个变通办法变通办法natanavra多亏了他。

However I read on developer forum,that it is working in 6.2 beta version of Xcode. Hope it do.

但是我在开发者论坛上读到,它在 Xcode 6.2 测试版中工作。希望它做。

回答by Viktor Kucera

I have experienced similar issues (IB localization in my case) on device. So general answer would be

我在设备上遇到过类似的问题(在我的情况下是 IB 本地化)。所以一般的答案是

Device- Uninstall app and clean project by Shift+CMD+K

设备- 通过 Shift+CMD+K 卸载应用程序并清理项目

Simulator- Go iOS simulator > Reset Content and Settings and clean project by Shift+CMD+K

模拟器- 转到 iOS 模拟器 > 重置内容和设置并通过 Shift+CMD+K 清理项目

These problems are really annoying. Along with poor ability to update localized strings is localization one of the biggest drawback of iOS development.

这些问题真的很烦人。除了更新本地化字符串的能力较差之外,本地化也是 iOS 开发的最大缺点之一。

回答by Leon Qiu

Another problem that could cause localization not work is the encoding of the strings file. Localizable.strings's encoding must be UTF-16. The default encoding of text file in xcode is UTF-8, that cause me spending a whole day to check why the localization not work.

另一个可能导致本地化不起作用的问题是字符串文件的编码。Localizable.strings 的编码必须是 UTF-16。xcode 中文本文件的默认编码是 UTF-8,这让我花了一整天来检查为什么本地化不起作用。

回答by Mehul Thakkar

In Xcode 6.0 and later, Localization not work by changing language in Simulator not working.

在 Xcode 6.0 及更高版本中,通过更改模拟器中的语言无法进行本地化。

You have to edit scheme before running your application.

您必须在运行应用程序之前编辑方案。

Go to Edit Scheme -> Run -> Options, change language here.

转到 Edit Scheme -> Run -> Options,在此处更改语言。

Now, Run Your Application. It will Work.

现在,运行您的应用程序。它会工作。

For more details, check this answer : Changing language on iOS 8.1 simulator does not work

有关更多详细信息,请查看此答案:在 iOS 8.1 模拟器上更改语言不起作用

回答by Dakusan

My problem for this was an incorrectly encoded character in the localization file.

我的问题是本地化文件中编码不正确的字符。