Contents

NSLocalizedString

Returns a localized version of a string from the default table, which Xcode autogenerates when exporting localizations.

Declaration

#define NSLocalizedString(key, comment)

Parameters

  • key:

    The key for a string in the default table.

  • comment:

    The comment to place above the key-value pair in the strings file. This parameter provides the translator with some context about the localized string’s presentation to the user.

Return Value

The result of sending localizedString(forKey:value:table:) to the main bundle, passing the specified key.

Discussion

Use this macro to automatically generate the default Localizable.strings file from your code when exporting localizations from Xcode or the genstrings utility. You can specify Unicode characters in key using \\Uxxxx—see the -u option for the genstrings utility.

The initial value for key in the strings file is key. To avoid collisions between words or phrases with multiple meanings, use a unique key for each use of the same phrase. Use the NSLocalizedStringWithDefaultValue macro to specify another value for key.

For information about inserting plural nouns and units into localized strings, see Localizing strings that contain plurals.

As of OS X 10.11 and iOS 9, Bundle is thread-safe. As such, you can safely call NSLocalizedString from any execution context.

NSLocalizedString(
    @"Did you know that venus flytraps have flowers"
        @" atop very long stems?\nThe long stem keeps"
        @" insects a safe distance away from their"
        @" digestive leaves below.",
    @"An interesting fact about venus flytraps shown"
        @" on the loading screen.");

See Also

Related Documentation

Localization