iOS is there a way to assign Localized String to a UILable from IB/storyboard
Asked Answered
D

2

11

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

Dupe answered 29/6, 2016 at 8:1 Comment(1)
May be this what you looking for: https://mcmap.net/q/1019619/-using-localized-text-in-uilabel-in-interface-builder ?Balling
M
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.

Magdau answered 29/6, 2016 at 8:14 Comment(5)
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.Dupe
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.Magdau
Replacing .strings files (uncheck and then check) worked!!. Thanks a lot.Dupe
so it's just an additional file? one for settings, second for code, third for storyboard?Holzer
@Holzer 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.Magdau
V
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!

Varicolored answered 29/6, 2016 at 8:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.