We use the localization tools and APIs provided by Apple, e.g. NSLocalizedString
.
- All user-facing text should be made localizable with the
NSLocalizedString
family of APIs with correspondingLocalizable.stringsdict
files for plurals. - The
key
parameter ofNSLocalizedString(_:comment:)
should be the text as it appears in English. Do not use other constants or identifiers, like"button.log-in.forgot-password"
. - Always fill out the
comment
parameter ofNSLocalizedString(_:comment:)
with a detailed description of the text with enough information such that a translator could understand the text without further context. Add detailed descriptions of positional parameters, and when multiple parameters are present, refer to them in the text based on their position in the English translation.- Examples:
NSLocalizedString("%d comments", comment: "Label displayed at the top of a thread. Parameter is the number of comments in the thread.") NSLocalizedString("Welcome to %@, %@!", comment: "Message shown at the top of the home screen after logging in. First parameter is the app name. Second parameter is the logged in user’s first name.")
- When formatting numbers and dates for display, use the “localized” API variants, such as
setLocalizedDateFormatFromTemplate(_:)
andlocalizedString(from:dateStyle:timeStyle:)
. - Consider using
String.variantFittingPresentationWidth(_:)
when creating adaptive widthString
s instead of using conditional logic.