Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS/iPhone: Nested Localizable.strings Files?

I'm creating an app that will have a number of variants.

These variants will be controlled by a few strings in multiple Localizable.strings files.

However, 90% of the strings will remain the same.

I'd like to have it so that each of the unique Localizable.strings files imports the "master" one, so that I don't have to go through each of the app variant files when I want to change a common string.

Is this possible?

like image 907
Chris Marshall Avatar asked Oct 10 '11 11:10

Chris Marshall


3 Answers

Two alternatives:

  1. Use custom wrapper functions around NSLocalizedString that do your hierarchical lookup for you, and then fall back to the NSLocalizedString mechanism for the default case.

    I previously wrote an answer about how to do this: Can .strings resource files be added at runtime?

  2. Use multiple .strings files per language. By default things are looked up in "Localizable.strings", but the NSLocalizedStringFromTable() function allows you to specify a custom "table" name. So if you passed in "Configuration" as the table name, it would look things up in the "Configuration.strings" file.

    I worked on an app that did this. We had two different .strings files. One controlled the branding settings (what name to use, what images to use, what servers to use, etc), and the other contained all of the actual translated strings. There would only be a single copy of the branding information in the app bundle, and we chose the correct variant to use at compile time with some custom scripts. It worked really really well.

like image 132
Dave DeLong Avatar answered Oct 20 '22 00:10

Dave DeLong


Unfortunately, Apple doesn't support that for its Localizable.strings files.

You could mimic that feature through a custom Ruby or Python script or just a Bash script using sed; the script could take the root .strings file and copy the contents into each variant's .strings file. It could even be a custom build step in Xcode.

like image 20
bdunagan Avatar answered Oct 20 '22 01:10

bdunagan


I'm not sure of what you want but if you just want to translate a few strings you could.

You can just translate a part of these strings, if there is no translation, ios will select the strings in the application language and display it. So the Localizable.strings in the application language could be consider like the master one.

like image 20
M to the K Avatar answered Oct 20 '22 00:10

M to the K