开发者

Is Localizable.strings required for the root language of an app?

As we're enabling our (English) application to be localized, we're replaced all in-line strings with NSLocalizedStrin开发者_运维百科g() calls. Since all of our English strings are all there in-line with the code, e.g. NSLocalizedString(@"OK, @"OK button in a message box"), is there any reason we need the English version of Localizable.strings? When we try removing the strings from the English Localizable.strings, the program seems to work fine. Just wanted to double check if there was some side-effect to not having that around. Thanks, alex


One of the main points of using the NSLocalizedString() macro is so that your programming code can be parsed with the genstrings command-line tool to generate the corresponding Localizable.strings file(s) (see Resource Programming Guide: About the String-Loading Macros and Using the Genstrings Tool to Create Strings Files).

That Localizable.strings file then serves as a starting point for your translators, to use to translate to another language. Without that file to work with, your translators would basically need access to your source code in order to see all the strings you want to use (which kind of defeats the purpose).

Yes, your English version works fine right now, since if a localized version of the string you try to get in code –– for example, NSLocalizedString(@"OK", @"") –– cannot be found in a .strings file, it simply uses the @"OK" string that you passed in.

Another reason why you should likely be keeping the English Localizable.strings is that you should generally try to avoid using high-ASCII characters in your code, but should use the full range of available characters in your actual user interface. For example, you may not want to put the following characters in your code, but would want to use them in your user interface:

… (horizontal ellipsis) (U+2026) “ (left double quotation mark) (U+201C) ” (right double quotation mark) (U+201D) ‘ (left single quotation mark) (U+2018) ’ (right single quotation mark) (U+2019)

So in code, you'd do something like this:

NSLocalizedString(@"Add Bookmark...", @"")

and then in your .strings file (which is UTF16, so this is fine):

"Add Bookmark..." = "Add Bookmark…";


It's not recommended to use the words as keys, if you want to change that Ok for something else and you have any other Localizable.strings, you will have to edit every single of them to update the Okkey.


Surely your translators will want your Localizable.strings file to work from. And want it to be ALL the strings.

(It is true that the system will fall back to the key, but relying on that seems like bad practice. And you'll find it more reliable to use proper punctuation in a Unicode file, which source code seldom is.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜