Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
687 views
in Technique[技术] by (71.8m points)

ios - What is the second parameter of NSLocalizedString()?

What is the *comment parameter in:

NSString *NSLocalizedString(NSString *key, NSString *comment)

If I do this:

NSLocalizedString(@"Hello_World_Key", @"Hello World")

and have two versions of a Localizable.strings (English and Spanish), does each need the entry:

English.lproj/Localization.strings: @"Hello_World_Key" = @"Hello World";

Spanish.lproj/Localization.strings: @"Hello_World_Key" = @"Hola Mundo";

Isn't the English one redundant?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The comment string is ignored by the application. It is used for a translator's benefit, to add meaning to the contextual usage of the key where it is found in your application.

For example, the Hello_World_Key key may take different values in a given language, depending on how formal or informal the Hello World phrase needs to be in that language ("What's up World", "Yo World", "Good Day World", etc.).

You can add a string in the comment field to hint this usage to the translator, who will (one would presume) be better able to localize your application.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...