When you work with user-facing text in your code, the way to indicate that it should be localized is to use the NSLocalizedString()
macro. The simple form of the macro takes 2 parameters, a key and a comment:
label.text = NSLocalizedString(@"welcome.heading", @"Friendly greeting at launch")
Note: some developers simply use the English string in place of the key. This is bad practice because as you evolve the user interface and change the English term. It also causes problems where a single word in English has multiple translations in a different language based on context.
It's also common to use
nil
for the comment. If you think the meaning of the term could be at all ambiguous, then it's best to include a comment to explain to the translator how it's used.
Each use of the NSLocalizedString()
should have a corresponding entry in your .strings
files. Linguan has a function to easily create those entries - the Scan Sources button.
Select the Localizable.strings
file. Notice that there are currently no entries in it
Click the Scan Sources button and Linguan will create entries for each the NSLocalizedString() usages in your source (where no existing entry exists).
This is a good time to edit the English entries and replace the key with the real text.
Tip: Select Last Scan in the Linguan navigator pane to see just the extracted entries.
Choose File, Save All to save all your changes to the project files.