Guus
Guus

Reputation: 399

XCode Storyboard Localization Duplicate Strings Merge?

I am currently working on an iOS app and localizing it into multiple languages but have faced an annoying (not breaking) issue.

When i would add a new localization for my storyboard xcode will automatically populate the strings, which is very nice. The issue i am having is that i have multiple interfaces which both have a back button. The text on these is of course the same and their translations are as well. The question i was wondering about, is it possible, without using strings.localizable, to somehow merge multiple object translations into one?

This is how it would currently look:

"Pnu-Ec-HAj.normalTitle" = "Back";
"Rtx-fT-rdc.normalTitle" = "Back";

But it would be way easier if there was a syntax such as

"Pnu-Ec-HAj.normalTitle", "Rtx-fT-rdc.normalTitle" = "Back"; (this syntax is not correct obviously)

I have looked around quite a while but have not found any answers to this question yet.

Thanks for reading.

Upvotes: 9

Views: 729

Answers (2)

Julian Vogels
Julian Vogels

Reputation: 698

I'd recommend referencing every text in your storyboard in code, and setting the text on viewDidLoad like, e.g.:

buyButton.titleLabel.text = NSLocalizedString(@"SHOP_BUY_BUTTON_TEXT",@"Button for buying product in detail view");

It's loads of work if you have huge storyboards, but in the end you have a clean Localizable.strings with concise keys and comments, providing necessary context for your translators.

I prefix the key with the section of the app, so for example SHOP_***, USER_SETTINGS_***, etc.

In addition, we use a service like OneSky to organize our translations online and update them from the cloud (not affiliated with them, and it's not without its teething problems either).

Upvotes: 3

GrizzlyBear
GrizzlyBear

Reputation: 1199

Unfortunately the .strings files are key-value files and, by nature, there must be a key (that is composed by the nib ID of the element followed by the property) and the associated string value.

As Apple describes in the precedent link:

The standard strings file format consists of one or more key-value pairs along with optional comments. The key and value in a given pair are strings of text enclosed in double quotation marks and separated by an equal sign.

then, your idea is not supported by the .strings files.

The only way to support that feature is by using the NSLocalizedString in code.

Upvotes: 0

Related Questions