jlmg5564
jlmg5564

Reputation: 1380

iOS localizable string with default values

I want to understand how localizable base string works in iOS. For example, in Android if I have got a default localizable file strings (base localization on iOS) like:

"title_app" = "Title"
"Copy" = "Copy";
"Edit = "Edit;"

And then I have got a Spanish localizable file like:

"Copy" = "Copiar";
"Edit" = "Editar";

Why on iOS if I set Spanish language on my device the key "title_app" doesn't appear? Because Android if doesn't find a key, it takes the key from the default language.

Sometines there are words that they don't need a translation. Or sometimes I have 10 languages and maybe one language needs a translation from a non translatable word. For example "title_app" = "My app". It will be the same in English, French, Italian, Spanish... but in chinese no. It is not efficient write the key on 10 files, repeating... imagine 10, 20 o 50 words.

Always Apple/iOS is far behind in matters of translation/localization compared to Android... :S

Talking about translation; sorry my bad english.

Upvotes: 0

Views: 1448

Answers (1)

Michael Teper
Michael Teper

Reputation: 4651

The NSLocalizedString macro takes two parameters, a key and a comment. The key will be looked up in Localizable.strings file, which is a simple key-value pair collection.

As @TheEye pointed out in the comments via the blog post link, you can exercise more control, and explicitly include a default value by using the NSLocalizedStringWithDefaultValue macro instead.

What you have to realize is that you have a choice: you can either use the simpler macro and treat your key as the default value (and iOS will fall back to that) or use the more specialized macro that is more verbose but gives you more control instead.

Note, this has already been discussed here: Fallback language iOS (with incomplete Localizable.strings file)

Upvotes: 0

Related Questions