XCode 5/iOS 7 - localization not working in simula

2019-01-14 15:16发布

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

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

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:

 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. Its still displaying in English:

enter image description here

Am I doing something wrong?

6条回答
混吃等死
2楼-- · 2019-01-14 15:45

Maybe you have run the app at some time where the file Localizable.strings already 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.

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

查看更多
淡お忘
3楼-- · 2019-01-14 15:47

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.

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-14 15:49

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

You have to edit scheme before running your application.

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

Now, Run Your Application. It will Work.

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

查看更多
放荡不羁爱自由
5楼-- · 2019-01-14 16:01

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

查看更多
Root(大扎)
6楼-- · 2019-01-14 16:06

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

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 Workaround by natanavra Thanks to him.

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

查看更多
forever°为你锁心
7楼-- · 2019-01-14 16:06

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

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

Simulator - Go iOS simulator > Reset Content and Settings and clean project by 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.

查看更多
登录 后发表回答