11

I want to assign NSLocalizedString(key, comment) to a UILabel from storyboard without creating an outlet for it.

Nagesh
  • 167
  • 1
  • 2
  • 11
  • May be this what you looking for: [http://stackoverflow.com/questions/10401987/using-localized-text-in-uilabel-in-interface-builder](http://stackoverflow.com/questions/10401987/using-localized-text-in-uilabel-in-interface-builder) ? – Ronak Chaniyara Jun 29 '16 at 08:06

2 Answers2

8

Just select your storyboard/xib, go to File Inspector. In the Localization part, you can tick the language you want. Then, it will create a .string file with all text used in storyboard. You'll just have to provide a translation for each text used in storyboard.

If no language appear in this part, you have to change values of Localization native development region in Info of your project.

AnthoPak
  • 4,191
  • 3
  • 23
  • 41
  • Thanks, I was able to create .strings files for my .xib, but these files are empty, can you give an example how I can add translated text for my labels. – Nagesh Jun 29 '16 at 09:25
  • Have you got text in your xibs ? For each label or button (or whatever contains text), Xcode will automatically fill the .string file for you. Put some text on your xib, and restart the operation in `Localization` part (uncheck then check). It will refresh the .string file for you. – AnthoPak Jun 29 '16 at 09:29
  • 1
    Replacing .strings files (uncheck and then check) worked!!. Thanks a lot. – Nagesh Jun 29 '16 at 09:52
  • so it's just an additional file? one for settings, second for code, third for storyboard? – user25 Feb 27 '18 at 11:43
  • 1
    @user25 Yes it's an additional .strings file. Usually, one per storyboard (or xib if you use them) and one for the strings included in your code. – AnthoPak Feb 27 '18 at 12:58
0

This might help, the official Apple guide to translating storyboard texts. I found it pretty straightforward. I am currently translating texts in-code, in the storyboard and in my info.plist files without issue. Hope it helps!

sinewave440hz
  • 1,265
  • 9
  • 22