Localization not working - Swift
Asked Answered
L

4

1

I have a problem with the localization of my app. I want to have french and english (default).

The localization seems to work with the Storyboard as text from there is translated to french (on simulator & iPhone in french). But the strings from Localizable.strings are not translated.

I checked the name of the file and it is correct "Localizable.strings". I validated the content of the files with "plutil -lint " and it was OK. Checking the target->build phases->copy bundle resources: the Localizable.strings is there.

In the code I am using:

NSLocalizedString("KEY", comment: "")

Checking the NSLocale of the simulator, it seems as the preferred language is french, so I do not understand why it is not working.

Any idea?

Thanks,

Henry

Lenzi answered 1/3, 2016 at 20:1 Comment(3)
This is not a help in any way - just want to say thanks for mentioning that the file must be named: "Localizable.strings" .. I had (for unknown reasons) named it something else - and just couldn't understand why it didn't work - until now. Thanks :-PElectroballistics
For change language "on the fly" you can use cocoapods.org/pods/L10n-swift.Zoochore
In my case I have replaced the file name with default name Localizable.strings. Now it is working fine.In my project so many pods with language changes, so it is not reloading immediately, after second time reopening the app then it's working. So I have replaced with default file name Localizable.strings.Flinn
B
1

You might be missing some settings in your scheme.

This tutorial on YouTube really helped me localize my last app. It's under 8 minutes. Hope it helps.

Bunyip answered 1/3, 2016 at 21:8 Comment(1)
Thanks, but I don't think this is a scheme issue. As it is not working, on the iPhone and on the simulator (only storyboard but not strings from code). Moreover, I did what was mentioned in the tutorial ;)Lenzi
L
1

I fixed my issue. There was a mistake in my Localizable.strings. I had the following for one line:

"..."; = "...";

It would be good if there was a tool to validate this.

Thanks for the effort,

Bye

Lenzi answered 2/3, 2016 at 19:16 Comment(0)
N
1

I faced same issue, but I found a mistake in Localizable.strings as user3900157. I missed semicolon at the end. After added semicolon to all sentences, it worked. Hope to help you.

Nakasuji answered 24/2, 2020 at 15:27 Comment(1)
For me it was an extra semicolon: ";;" which builds without warnings, for some reasonMarketplace
F
0

I have got same issue in Xcode 12.5

My Issues: I worked with English and Arabic text. English text was working fine but not able to extract Arabic Text. Have tried all solutions.

My Solution 1: Actually I had copied and pasted Arabic text from Google which caused issue in Xcode(Xcode was not able to read those texts.) So I copied Arabic texts first in Notes App and then copied to Xcode.

My Solution 2: I have tracked this issue after 4-5 afters. I checked the texts which are working fine in Arabic and checked the last line from where texts are not working. So i found that Arabic text was pasted improperly. So I cut that text and copied to Notes App and copied from Notes App and pasted back to code.

And Boom It worked.

Foresheet answered 1/10, 2021 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.