iOS Localization (Localizable.strings) not working
Asked Answered
E

5

6

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.

Extramural answered 24/12, 2012 at 13:22 Comment(3)
Did you put the strings file into the localised resources folder?Aldred
How did you add Localizable.strings to your project? Did you go through "New/File..." dialog, and picked "Strings File" under the "iOS/Resource" tab?Pulley
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.Hanuman
C
23

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
Cliffordclift answered 24/12, 2012 at 13:25 Comment(7)
what do you mean with "ultraclean"? remove my app from simulator or the project?Extramural
sorry, i didnt seen the tutorial. (iPad bug)Extramural
function key + shift + k - do ultraclean (clean all targets)Cliffordclift
For me this solved the issue that I would get ERR appearing instead of error. This answer relies on the fact that your localisation is set up and working but that the links need to be refreshed. The other answers below seem to deal more with problems getting it set up :)Pampas
Wow, way to make this easy Apple! BTW by "ultraclean" I think he means clean the build folder which you can do by going to the Product menu in Xcode, then hold the Option button and select "Clean Build Folder..."Flog
Btw the shortcut for this is "option-shift-command-k", which solved the problem for me. fn-shift-K doesn't seem to do anything. For some reason reviewers rejected my edit. (shrug)Missy
Cleaning, deleting app and re-installing did the trick. Thank you!Kolinsky
M
8

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!

Modest answered 8/2, 2013 at 18:9 Comment(1)
TADA! Thanks! My strings wasn't added to target neither! Probably a merge error...Homozygote
I
3

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")
Islander answered 15/3, 2020 at 16:27 Comment(0)
N
1

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

Natividadnativism answered 16/1, 2014 at 10:14 Comment(0)
U
0

What happens if you use it as follows.

self.label1.text = [NSString stringWithFormat:@"%@",NSLocalizedString(@"ERR", nil)];
Updo answered 24/12, 2012 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.