简体   繁体   English

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

[英]Xcode 5/iOS 7 - localization not working in simulator

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 文件:

在此处输入图片说明

The French file has the correct (well as far as Google translate goes) French versions of my string:法语文件具有正确的(就谷歌翻译而言)我的字符串的法语版本:

在此处输入图片说明

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.但它不是从正确的 localizable.strings 文件中提取的。 It's still displaying in English:它仍然以英文显示:

在此处输入图片说明

Am I doing something wrong?难道我做错了什么?

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.本地化似乎不适用于 xCode 6.1 和 8.1 模拟器。 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 Workaround by natanavra Thanks to him.感谢他,我从natanavra 的Workaround 中得到了这个解决方法

However I read on developer forum ,that it is working in 6.2 beta version of Xcode.但是我在开发者论坛上读到,它在 Xcode 6.2 测试版中工作。 Hope it do.希望它做。

Maybe you have run the app at some time where the file Localizable.strings already existed but has not been localized yet.也许您在某个时间运行了该应用程序,其中文件Localizable.strings已经存在但尚未本地化。 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.这可能会导致问题。

Try to delete the app completely from the simulator and build an run again.尝试从模拟器中完全删除应用程序并再次构建运行。

I have experienced similar issues (IB localization in my case) on device.我在设备上遇到过类似的问题(在我的情况下是 IB 本地化)。 So general answer would be所以一般的答案是

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 开发的最大缺点之一。

Another problem that could cause localization not work is the encoding of the strings file.另一个可能导致本地化不起作用的问题是字符串文件的编码。 Localizable.strings's encoding must be UTF-16. Localizable.strings 的编码必须是 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. xcode 中文本文件的默认编码是 UTF-8,这让我花了一整天来检查为什么本地化不起作用。

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 模拟器上更改语言不起作用

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

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

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