Jonathan Gurebo
Jonathan Gurebo

Reputation: 167

iOS Localization (Localizable.strings) not working

I have an app with an "Error" message. I want to translate this error message.

OK, first I created a file named "Localizable.strings". In the file I wrote:

"ERR" = "Error";

then in my .m file I wrote:

self.label1.text = NSLocalizedString(@"ERR", nil);

and this will not work. I also tried (of course) to make the file localized and added more languages. But it will not work.

Upvotes: 6

Views: 14483

Answers (5)

Badr Bujbara
Badr Bujbara

Reputation: 8691

If localized string doesn’t show up, there might be another Localizable.strings in the pods so:

1 - Change “Localizable.strings" name to, say, Localized.strings

2 - Specify it as the tableName argument

let myStr = NSLocalizedString("key", tableName: "Localized", comment: "comment")

Upvotes: 3

Misha
Misha

Reputation: 5380

Follow the following tutorial to create language files, than after filling them do the followihg:

  1. Do ultraclean (function key + shift + k)
  2. Rebuild
  3. Remove your app
  4. Install your app again

Upvotes: 23

Jayprakash Dubey
Jayprakash Dubey

Reputation: 36447

The below mentioned steps might help you :

  1. Select "New File" by right click on files in left-pane of Xcode
  2. A window appears as show in screenshot 1
  3. Select "String" file
  4. Rename file as "Localizable.strings" as show in screenshot 2
  5. Add required text into file in following format : "newStringItem" = "This is new String item";

  6. Now the file contents can be used as NSLocalizedString(@"newStringItem", @"") which returns corresponding string.

Vola! Done with Localization!

Screenshot 1

Screenshot 2

Upvotes: 1

YaDa
YaDa

Reputation: 1273

I had the same problem. I stared at it for days, until I peeked into the app bundle and saw that none of my .strings files were copied...

The solution is to create a build phase to copy the string files: (adapted from here)

  1. Goto Target\Build phases
  2. Click "Add build phase" button and select "Copy files"
  3. select "Resources" in "Copy files" phase
  4. add Localizable.strings and any other string files in the project.

TADA!

Upvotes: 8

BarryK88
BarryK88

Reputation: 1806

What happens if you use it as follows.

self.label1.text = [NSString stringWithFormat:@"%@",NSLocalizedString(@"ERR", nil)];

Upvotes: 0

Related Questions