Swift: Localization in Storyboard - Labels not added to Main.strings?
Asked Answered
T

5

13

When I try to localize my app and I create a new Main.strings file for the target language, everything I have created in interface builder (labels, buttons, ...) is added to the new Main.strings files (base and language versions) and I can localize the text accordingly.

But when I later add a label or a button to a ViewController in interface builder, it is not automatically added to the Main.strings files for the base and language version.

So, how can I find out what the ObjectID for the button/label is so that I can add it to the strings files?

Or is there another way to force Xcode to add newly added labels and buttons to those files automatically?

Tillage answered 13/1, 2018 at 12:52 Comment(1)
Possible duplicate of Is it possible to update a localized storyboard's strings?Firstfoot
H
26

After selecting UILabel from storyboard, You can find object id of UILabel in right panel:

enter image description here

Then you can set text of label as below in your Main.string file:

"sxl-NO-5WX.text" = "Phone";
Highbinder answered 13/1, 2018 at 13:17 Comment(2)
Was about to give the exact same answer. Took me a day to find this out back then :DAudreyaudri
Is there any way to add them automatically?Barilla
M
2

Dhaval Bhimani's answer is the easiest solution for localizing a small number of newly added view components. If you want to regenerate all the localizations for a storyboard, select the Main.storyboard-> deselect the localization check boxes for all the languages. check the 'Delete localized resource files from disk' check box enter image description here now make sure your newly added labels and buttons are there and localize again by selecting languages. Just in case backup your string files before that

Mizuki answered 14/10, 2018 at 7:42 Comment(0)
D
1

Use ObjectID.text for UILabel

Use ObjectID.normalTitle for UIButton

Example:

/* Object ID of UILabel */
"GWb-TZ-iGk.text" = "I am label";

/* Object ID of UIButton */
"H6f-pG-K8Z.normalTitle" = "I am button";
Determinant answered 9/5, 2020 at 11:21 Comment(0)
S
1

Easy XIB and Storyboard Localization - Very efficient and simple method

This repository serves as an example on how to localize some UIKit controls:

UILabel, UIButton, UITextField placeholder, UISegmentedControl, UIBarItem for tab bar items and navigation bar items, UINavigationItem, Review Localizable.swift to check it.

https://github.com/emenegro/xib-localization

English

Spanish

Stroh answered 4/7, 2021 at 9:56 Comment(2)
Add some code otherwise this can be share in comment also.Twila
Code is in the repository mentioned in the answer.Stroh
W
0

Use ibtool to extract the strings in your storyboard.

Open the Terminal application Locate your Base.lproj directory Use this line to extract the strings:

ibtool MainStoryboard.storyboard --generate-strings-file file_name.strings

After ibtool extracts the strings to file_name.strings, you can copy and paste it to your original .strings file

(Originally appread here Is it possible to update a localized storyboard's strings?)

Walworth answered 22/9, 2019 at 6:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.