Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Localization Guide
Contents
Contents
Contents
Tables
Locking levels 61
Localization is the process of translating your app into multiple languages. But before you can localize your
app, you internationalize it. Internationalization is the process of making your app able to adapt to different
languages, regions, and cultures. Because a single language can be used in multiple parts of the world, your
app should adapt to the regional and cultural conventions of where a person resides. An internationalized app
appears as if it is a native app in all the languages and regions it supports.
The App Store is available in over 150 different countries, and internationalizing your app is the first step to
reach this global market. Using iTunes Connect, you specify whether your app is available in all territories or
specific territories. Then you customize your app for each target market that you want to support. Users in
other countries want to use your app in a language they understand and see dates, times, and numbers in
familiar, regional formats.
At a Glance
Xcode supports incremental localization of your project. First you internationalize your user interface and code
during development. Then you test your app using pseudolocalizations and different region settings. When
you are ready to localize your app, you export the localizable text using standard file formats and submit them
to a localization team for translation into multiple languages. While you are waiting for these translations, you
can continue developing your app and perform additional localization steps yourselfperhaps add
language-specific audio and image files to your project. Then import the localizations into your project and
thoroughly test your app in each supported language and region. During the next iteration of your app, you
only translate changes and add additional languages.
Use base internationalization to separate user-facing text from your .storyboard and .xib files.
In Interface Builder, use Auto Layout so views adjust to the localized text.
Use standard APIs to handle the complexity of different writing systems and locale formats.
Adhere to the users settings when formatting, sorting, searching, and parsing data.
If the app supports right-to-left languages, mirror the user interface and change the text direction as
needed.
Related Chapter: Internationalizing the User Interface (page 24), Internationalizing Your Code (page
30), Formatting Data Using the Locale Settings (page 37), Supporting Right-To-Left Languages (page
50)
Xcode doesnt translate text for you. For links to third-party localization vendors, see Build Apps for the World.
Related Chapter: Localizing Your App (page 60)
Related Chapter: Internationalizing the User Interface (page 24), Testing Your International
App (page 79)
See Also
The following documents provide more information about related topics:
Xcode Overview describes Xcode features and contains links to other Xcode books.
Data Formatting Guide describes how to present and interpret calendrical and numerical data according
to the users region settings.
Date and Time Programming Guide describes how to manage dates and times according to different
calendars and time zones in use around the world.
Internationalization and Localization for OS X provides code samples that illustrate internationalization
and localization techniques and APIs.
Before you submit your localized app to the App Store or Mac App Store, add territories and localize your
metadata using iTunes Connect:
Viewing and Changing Your Apps Metadata in iTunes Connect Developer Guide
Displaying on the Store in More Than One Language (Optional) in iTunes Connect Developer Guide
For iOS and Mac, the language, region, and calendar are user preferences. The language setting determines
which localization the app uses. The region setting determines the format of datasuch as dates, times, and
numbersand also cultural conventions of the area. For Mac, you can also customize regional formats. For
iOS and Mac, you can choose a different calendar that may change the era and affect other calendar calculations.
For iOS, changing the language restarts Springboard and quits running apps. So the next time you launch an
iOS app, it uses the new language setting. For Mac apps, the language doesnt change until you restart the
app. To localize all apps and the entire desktop on a Mac, you log out and log in. For iOS and Mac, the region
and calendar settings can be changed at any time, even when your app is running. An internationalized app
respects all these user settings and takes the appropriate action when they change.
Before internationalizing your app, review the language, region, and calendar settings on the target device.
Notice how localized apps adjust to the changes you make to these settings.
10
11
2.
3.
12
For example, see how Calendar localizes its views in Spanish, Chinese, and Arabic below. In Arabic, the title
and location text fields are right-aligned because Arabic is a right-to-left language.
13
2.
3.
14
15
2.
3.
16
The language, region, and calendar settings are in the Language & Region pane of System Preferences. You
can also create custom regional data formats on a Mac.
2.
Either click the Add button (+) to add a language, or drag a different language to the top of the Preferred
languages list.
17
If OS X or an app supports the primary language, menus and messages are shown in that language. If it
doesnt, it uses the second language in the list, and so on.
3.
If you click the Add button, in the dialog that appears, select a language, and click Add. In the dialog that
appears, click Use [Language] to move the language to the top of the Preferred languages list.
18
2.
3.
19
4.
In the General pane, choose the language to use for showing dates, times, and numbers, and set formats
for numbers, currency, and measurements.
20
5.
In the Dates and Times panes, you can create custom number and date formats by entering text and
dragging elements.
21
22
2.
23
Xcode provides several technologies to help you develop an internationalized app. Xcode separates user-facing
text from your views and layout so user-facing text can be easily translated independent of your Xcode project.
Xcode also provides tools to maintain this separation when you change the user interface. In addition, you
may have different sets of other types of resource files for each language you support.
24
Use leading and trailing attributes. When adding constraints, use the attributes leading and trailing for
horizontal constraints. For left-to-right languages, such as English, the attributes leading and trailing are
equivalent to left and right. For right-to-left language, such as Hebrew or Arabic, leading and trailing
are equivalent to right and left. The leading and trailing attributes are the default values for horizontal
constraints.
Pin views to adjacent views. Pinning causes a domino effect. When one view resizes to fit localized text, other
views do the same. Otherwise, views may overlap in some languages.
Constantly test your layout changes. Test your app using different language settings, as described in Testing
Your International App (page 79).
Dont set the minimum size or maximum size of a window. Let the window and its content view adjust to
the size of the containing views, which may change when the language changes.
Auto Layout is enabled by default when you create a new project. To enable Auto Layout for an older project,
read Adopting Auto Layout in Auto Layout Guide . To learn how to add constraints and resolve constraint issues,
read Auto Layout Guide .
In project navigator, select the .storyboard or .xib file you want to preview.
2.
3.
In the assistant editor jump bar, open the Assistant pop-up menu, scroll to the Preview item, and choose
the .storyboard or .xib file.
If a preview of the apps user interface doesnt appear in the assistant editor, select the window or view
you want to preview in the icon or outline view.
25
4.
In the assistant editor, choose the pseudolocalization you want to use from the language pop-up menu
in the lower-right corner.
26
For example, choose Double-Length Pseudo-Language from the menu to replace all user-facing strings
with duplicate strings. A preview of the localization appears in the assistant editor.
In the project navigator, select the project (not a target) and click Info.
27
2.
If necessary, click the disclosure triangle next to Localizations to reveal the settings.
3.
4.
In the dialog that appears, specify the development language for your .storyboard and .xib files.
Select the .storyboard and .xib files in the Resource File column and the development language in
the Reference Language column.
Xcode modifies your project folder according to the selections you make in this dialog. Xcode creates a
Base.lproj folder in your project folder and adds to it the resource files you select. Xcode creates a
language folder for the development language but only adds resources that need translation to the folder.
For example, if you select English as the development language, Xcode inserts the resource file in the
Base.lproj project folder but not the en.lproj folder because the resource is already in English.
If no resources appear in the dialog, add your .storyboard and .xib files to a language, as described
in Adding Additional Resources to Language Folders (page ?), and repeat these steps.
28
5.
29
In addition to internationalizing your user interface, write code that handles text in multiple languages. First
store international text in strings files similar to the strings files used by base internationalization in
Internationalizing the User Interface (page 24). Also use language and locale-sensitive APIs for enumerating,
searching, and sorting text in your code. Use standard text views for displaying and parsing text input as well.
Let these APIs handle the complexity of different writing and input systems for you.
where @"RunningDistance" is the key for text that is retrieved from a localized strings file. The @"distance
for a marathon" parameter is a comment about the key-value pair stored in the strings file as a hint to
localizers. If you want different behavior, use one of the other NSLocalizedString macros that take more
parameters, described in Foundation Functions Reference .
30
Tip: Dont overload keys or compose phrases from multiple keys. Some languages have gender articles, adjective
endings, and completely different word order. Instead, add a separate key-value pair to the strings file for all
unique phrases.
For example, replace these key-value pairs:
/* Go to next page/chapter */
"GoToNext" = "Go to next %@";
"chapter" = "chapter";
"page" = "page";
/* Go to next page */
"GoToNextPage" = "Go to next page";
Dont put numbers in localizable strings because different regions can use different numbers.
You dont need to store all your key-value pairs in the same strings files. You can use other NSLocalizedString
macros to create separate strings files and optionally, store them in different bundles. For more information
on NSLocalizedString macros, read String Resources in Resource Programming Guide .
To retrieve a localized string from a strings file, rather than adding it to a strings file, use the
localizedStringForKey:value:table: method in the NSBundle class. When the strings file corresponding
to the specified table is not in your project, the NSLocalizedString macros and the
localizedStringForKey:value:table: method return the value parameter as the localized string.
Later, when you import localizations, as described in Importing Localizations (page 65), the localized strings
files are added to your project. (Alternatively, you can generate the development language strings files from
NSLocalizedString macros directly, as described in Creating Strings Files for User-Facing Text in Your
Code (page 86).)
If your strings contain plurals of nouns or units of measurement, read Handling Noun Plurals and Units of
Measurement (page 71) for how to extend this mechanism for languages that have different plural rules.
31
User Character
UTF-16
UTF-32
D85E DFFD
27BFD
Video: WWDC 2013 Making Your App World-Ready: International Text > Composed Character Sequences
Enumerating Strings
Enumerate strings by composed character sequence, word, sentence, or paragraph, not individual characters
in a string. To enumerate a string by composed character sequence, use the
enumerateSubstringsInRange:options:usingBlock: method and pass
NSStringEnumerationByComposedCharacterSequences as the options parameter. To enumerate a string
by word (skipping over punctuation), pass NSStringEnumerationByWords as the options parameter.
32
If the string is
and you pass NSStringEnumerationByWords as the options parameter, the following words are returned:
Notice that spaces and punctuation are not included in the words.
Video: WWDC 2013 Making Your App World-Ready: International Text > String APIs: Iteration
Searching Strings
To search the contents of a string or verify the presence of a string within a string using locale-sensitive
comparison algorithms, use the rangeOfString:options:range:locale: method, passing the current
locale as the locale parameter. The constants you can combine and pass as the options parameter are:
NSCaseInsensitiveSearch
33
For example, if you are searching for user text in a string, pass the NSCaseInsensitiveSearch and
NSDiacriticInsensitiveSearch constants as the options parameter to the
rangeOfString:options:range:locale: method. Typically, searching text is a case and diacritic insensitive
operation, but sorting text is case and diacritic sensitive.
Sorting Strings
For text you display to users, use locale-sensitive APIs for sorting and comparing strings. Different languages
and regions have different sort order standards. For example, in French the diacritics are significant, and in
English they are not. In some languages multiple letters are combined and affect the sort order.
To use the locale-sensitive comparison algorithms, use the localizedStandardCompare: method which
produces the same results as the Finder.
If you dont want the same results as the Finder, use the compare:options:range:locale: method, passing
the current locale as the locale parameter, or the localizedCompare: method.
Dont use the localizedCaseInsensitiveCompare: method for sorting.
Video: WWDC 2013 Making Your App World-Ready: International Text > String APIs: Sorting
Displaying Text
Use standard views and controls that handle the complexity of Unicode text layout and display for you.
Characters in a string do not directly correspond to text rendered on the screen. What appears on the screen
is a sequence of glyphs. A glyph is the smallest displayable unit in a font. A glyph may represent one character,
more than one character, or part of a character. The mapping of characters to glyphs is not simpleit can be
many-to-many. In addition, the order and position of glyphs in a line is complex. The standard views and
controls even lay out bidirectional text properly for youfor example, the order of characters in a string
containing an English word followed by a Hebrew word is not the same order used to lay out the text in a
view, as described in Handling Bidirectional Text (page 53).
If you need to write custom display code, use the appropriate low-level text APIs. To learn about the text classes
for iOS, read Text Programming Guide for iOS and for Mac, read Text Layout Programming Guide .
34
The returned string is a language ID, as described in Language and Locale IDs (page 92), that identifies a
written language or dialect.
To get the set of languages that the user enables:
NSArray *languages = [[[UIApplication sharedApplication] textInputMode]
activeInputModes];
35
them. To handle varying input formats in your text views, use Interface Builder to add data detectors to your
text views. A data detector identifies addresses and phone numbers in many different international formats
and optionally turns them into links.
To detect this type of data in strings programmatically, read NSDataDetector Class Reference .
36
Different countries and regions have different conventions for formatting numerical and time-based information.
Locale settings provide information about the formats used by the current user and must be considered when
writing code that handles user-facing data types. The user sets the locale by choosing a region in Settings on
iOS devices and System Preferences on a Mac. The user can also change locale settings while the app is running.
Therefore, if you manipulate data objects in your code and then present them to the user, use the locale APIs
to format the data correctly.
You do not need to know how to format data in all the different locales. You can use preset styles that
automatically generate locale-sensitive formats. You can use custom formats as long as you convert them to
locale-sensitive formats before presenting them to users. This chapter explains how to write locale-sensitive
code.
Language (Region)
Dates
Times
Numbers
7:08:09 AM PST
1,234.56
1/5/14
7:08 AM
$4,567.89
07:08:09 PST
1.234,56
05/01/14
07:08
4.567,89
English (Germany)
37
On a Mac, you can preview modified locale preferences in System Preferences. When you choose a geographic
region from the Region pop-up menu, samples of the date, time, and number formats appear. This screenshot
shows sample data formats when English is the language and Japan is the region:
Mac users can also customize the formats of dates, times, and numbers by clicking the Advanced button, as
described in Changing the Language and Region Preferences on Your Mac (page 17).
38
If you use the autoupdatingCurrentLocale method, the property values can change when the user changes
the region settings. However, you are not notified if the returned object changes.
To observe locale preference changes, read Registering for Locale and TimeZone Changes (page 49).
Tip: The system settings are not the same as the users settings. Dont use the systemLocale class method
to get the users locale.
Pass the NSLocaleCurrencySymbol key to get a string representation of the locales currency symbol:
NSString *currencySymbol = [[NSLocale currentLocale]
objectForKey:NSLocaleCurrencySymbol];
For a complete list of locale property keys, see NSLocale Component Keys.
The returned string is a language ID that identifies a written language or dialect, as described in Language
and Locale IDs (page 92).
39
2.
If you pass the language ID as the locale ID parameter, a locale for the language is returned. For example,
if you pass de-CH as the language, the Switzerland locale is returned.
3.
The format of the string is [Language] ([Dialect]). For example, if the language ID is de-CH, the localized
language string is Deutsch (Schweiz). If the language ID is de, the localized language string is Deutsch.
2.
3.
Get the beginning and ending symbols for quotes from the locale object.
bQuote = [locale objectForKey:NSLocaleQuotationBeginDelimiterKey];
eQuote = [locale objectForKey:NSLocaleQuotationEndDelimiterKey];
4.
40
Table 4-2 shows the results when myText is @iPhonefor different regions.
Table 4-2
Region
quotedString = @"%@iPhone%@"
China
iPhone
France
Japan
Formatting Strings
If available, use the alternative, locale-sensitive NSString method for user-facing text. There are locale-sensitive
methods for creating strings with formats, changing the case, obtaining ranges within a string, and comparing
strings.
This method uses the system locale. To specify the users locale preference, pass [NSLocale currentLocale]
as the locale parameter to either the initWithFormat:locale: or initWithFormat:locale:arguments:
method. For best results, use data-specific formatter objects and preset styles, described in Formatting Dates
and Times (page 42) and Formatting Numbers (page 45).
41
uppercaseStringWithLocale:
lowercaseStringWithLocale:
capitalizedStringWithLocale:
If you pass nil as the locale parameter, the system locale is used, which is incorrect. To specify the users locale
preference, pass [NSLocale currentLocale] as the locale parameter.
For example, specify a medium style to abbreviate textsuch as Jun 10, 2013by passing
NSDateFormatterMediumStyle as the style parameter. Specify a short style for numerical only
representationssuch as 6/10/13 or 11:03 AMby passing NSDateFormatterShortStyle as the style
parameter. Table 4-3 shows the results of using preset formats when English is the language and United States
is the region.
Table 4-3
Preset date and time styles in English for the United States
Style
Date
Time
Description
Short
6/10/13
11:03 AM
Numeric only
Medium
11:03:15 AM
Abbreviated text
Long
11:03:15 AM PDT
Full text
42
Style
Date
Time
Description
Full
Complete details
Output suppressed
No Style
Table 4-4 shows the results of passing NSDateFormatterMediumStyle for the date style and
NSDateFormatterShortStyle for the time style for different languages and regions.
Table 4-4
Language (Region)
Medium style
Short style
Jun 6, 2013
10:14 AM
French (France)
6 Jun 2013
10:14
Chinese (China)
Video: WWDC 2013 Making Your App World-Ready: Data Formatting > Preset Date Styles
2.
43
Set the format of the NSDateFormatter instance to the locale-sensitive format string.
dateFormatter.dateFormat = localeFormatString;
4.
Use the stringFromDate: method to get a localized string representation of the date.
NSString *localizedString = [dateFormatter stringFromDate:[NSDate date]];
For example, if you dont convert the @MMM d string to a locale-sensitive format, the results are not localized,
as shown in the second column in Table 4-5.
Table 4-5
Language (Region)
MMM d
dMMM
Nov 13
Nov 13
French (France)
nov. 13
13 nov.
Chinese (China)
Video: WWDC 2013 Making Your App World-Ready: Date Formatting > Custom Date and Time
Styles
44
1.
2.
Replace NSDateFormatterMediumStyle with the style you expect the user to enter.
3.
If the input string is not expected to contain a time, set the time style to none.
dateFormatter.timeStyle = NSDateFormatterNoStyle;
4.
5.
For example, if the locale is United States, the input string is 9/3/14, and the preset style is
NSDateFormatterShortStyle, the date is interpreted as 2014-09-03 07:00:00 +0000. However, if the
locale is Germany, the date becomes 2014-03-09 08:00:00 +0000.
Formatting Numbers
Locale settings affect the format of numberssuch as the decimal, thousands separator, currency, and
percentage symbols. For example, the number 1,234.56 is formatted as 1.234,56 in Italy. So use the
NSNumberFormatter class to create localized string representations of NSNumber objects.
45
Note: The NSNumberFormatter class is not thread-safe. See Threading Programming Guide for
details.
Table 4-6 lists the preset styles available and compares United States preset formats to other regions.
Table 4-6
Style
Decimal
Formatted string,
Language (Region)
1,234.56
1.234,56
Italian (Italy)
Currency
$1,234.56
Chinese (China)
Percent
123,456%
Arabic (Egypt)
Scientific
1.23456E+03
1,23456E3
Italian (Italy)
Spell Out
46
2.
Replace NSNumberFormatterDecimalStyle with the style you expect the user to enter.
3.
4.
47
Table 4-7
Calendar unit
Possible values
Year
Era
AD, Heisei
Lengths of months
From 5 to 31 days
Therefore, use the NSCalendar class for all calendrical calculations such as computing the number of days in
a month, computing delta values, and getting components of a date. You can use an NSDate object for internal
calculations but use an NSCalendar object for computations of user-facing dates.
To get the calendar for the users locale, use the currentCalendar class method in NSCalendar class:
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
2.
48
Tip: Any time you fetch or set the year, also fetch or set the era. Era is not required for the Gregorian calendar,
but it is for several other calendars.
For more information on using the NSCalendar and NSDateComponents classes, read Date and Time
Programming Guide or watch WWDC 2013: Solutions to Common Date and Time Challenges.
49
Your user interface should be mirrored when displaying right-to-left languages. If you use base
internationalization and Auto Layout, most of the user interface will appear mirrored automatically for you.
The text direction changes to right-to-left with the exception of phone numbers and country codes which are
always left-to-right. Some views and controls in your user interface may not change direction automatically
which you can fix programmatically.
50
user interface appears mirrored in right-to-left languages. For Mac apps, most controlssuch as segmented
controls, progress indicators, and outline viewsalso appear flipped. iOS doesnt automatically mirror controls,
so if you want this behavior for an iOS app, subclass the control and override the drawing methods.
Types of controls and content that should not flip in a right-to-left language are:
Clocks
Use base internationalization and if necessary, provide language-specific images and audio files for the
right-to-left languages that you support. To localize other resource files, read Adding Additional Resources
You Want to Localize (page ?).
Thoroughly test your user interface in a right-to-left language, as described in Testing Right-To-Left
Languages (page 81), and only if necessary, modify your code to support right-to-left languages.
51
However, if you want to align a control to the right in a left-to-right language (and to the left in a right-to-left
language), get the layout direction, as described in Getting the Layout Direction (page 52), and set the alignment
to NSLeftTextAlignment for a right-to-left language.
For Mac apps:
if ([NSApp userInterfaceLayoutDirection] ==
NSUserInterfaceLayoutDirectionRightToLeft) {
[[(NSMutableParagraphStyle *)paraStyle setAlignment:NSLeftTextAlignment];
else{
[[(NSMutableParagraphStyle *)paraStyle setAlignment:NSRightTextAlignment];
52
53
Conversely, to always display a variable right-to-left in a left-to-right language, insert a right-to-left embedding
(RLE) character, U+202B, before the variable and a pop directional formatting (PDF) character, U+202C, after
the variable.
If a variable appears at the beginning of a string, natural direction causes the entire string to use the directionality
of the variable. This is incorrect behavior if the variable directionality is unknownfor example, the variable
could be an Arabic or English user name. In this case, insert a right-to-left mark (RLM) character, U+200F, before
the variable for right-to-left languages, or a left-to-right mark (LRM) character, U+200E, before the variable for
strings for left-to-right languages. Use this technique for left-to-right localizations even if you dont have
localizations for right-to-left languages.
2.
3.
4.
In the outline view, click the disclosure triangle next to the Table Column and select its Text Field Cell.
54
5.
55
Flipping Toolbars
Toolbars dont automatically mirror in right-to-left languages. You can fix this programmatically by either
reversing the order of toolbar items in the awakeFromNib method or implementing the
toolbarDefaultItemIdentifiers: delegate method to return items in reverse order.
For example, add this code fragment to the App Delegates awakeFromNib method implementation where
toolbar is the NSToolbar object you want to flip.
// Flip toolbar items order for RTL support
if ([NSApp userInterfaceLayoutDirection] ==
NSUserInterfaceLayoutDirectionRightToLeft) {
NSArray *toolbarItems = [[self.toolbar items] copy];
for (NSToolbarItem *item in toolbarItems) {
[self.toolbar removeItemAtIndex:toolbarItems.count-1];
[self.toolbar insertItemWithItemIdentifier:item.itemIdentifier atIndex:0];
}
}
If the images on controls are left-to-rightfor example, left and right arrowsthey should be flipped as well.
Flipping Images
To flip image resources for right-to-left languages, choose one of three approaches. You can provide separate,
localized resources for the right-to-left languages you support, as described in Adding Additional Resources
You Want to Localize (page ?). You can add alternate, right-to-left image resources to your Xcode project,
and in your code, use the alternate image for right-to-left languages. You can also flip images programmatically
for right-to-left languages in the App Delegates awakeFromNib method.
For example, invoke this flipImage: method to return a mirrored image.
- (NSImage *)flipImage:(NSImage *)image
{
NSImage *existingImage = image;
NSSize existingSize = [existingImage size];
NSSize newSize = NSMakeSize(existingSize.width, existingSize.height);
NSImage *flippedImage = [[[NSImage alloc] initWithSize:newSize] autorelease];
[flippedImage lockFocus];
56
[[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
[flippedImage unlockFocus];
return flippedImage;
}
2.
Choose a region that uses the language from the Region pop-up menu.
The calendar setting automatically changes to match the region.
57
3.
Click Advanced.
4.
In the General pane, choose the right-to-left language from the Format language pop-up menu.
58
Alternatively, change the language and region in the scheme editor, described in Testing Specific Languages
and Regions (page 83). To change the text direction without changing the language or region, read Testing
Right-to-Left Languages (page 81).
59
When you are done internationalizing the apps user interface and code, begin the localization process. Export
all the development language strings files that contain user-facing text to a standard XML Localization
Interchange File Format (XLIFF). Submit the XLIFF file to a localization team for translation into multiple
languages. Continue developing your app while waiting for the translations. Import the XLIFF translations into
the project and test the app in each language you added. Repeat the process as needed, translating just the
changes between each app revision. As necessary, perform additional localization steps yourself.
Choosing Languages
You can choose from more than 100 different languages and dialects designated by regions to localize your
app. However, the more general you make your localized resources, the more regions you can support with a
single set of resources. This can save a lot of space in your app bundle and help reduce localization costs. For
example, if you dont need to distinguish between different regions that use the English language, you can
60
add English to support users in the United States, United Kingdom, and Australia. Even if you provide
region-specific resources always provide a complete set of language-specific resources for all the languages
you support.
When searching for resources, the bundle APIs try to find the best match between the languages the app
supports and the users language and region settings. The region-specific resource folders are searched before
the language-specific resource folders. For example, if you add English (United States), English (United Kingdom),
and English (Australia) to your project, the bundle APIs search the appropriate region-specific folders first,
followed by the English language folder. For more information about how the bundle APIs find localized
resources, read The Bundle Search Pattern in Bundle Programming Guide .
If you are unsure about what languages to add, consider the primary languages used in the App Store territories
you choose in iTunes Connect to market your app. The App Store territories are listed in App Store Territories
in iTunes Connect Developer Guide .
Locking Views
In Interface Builder, lock views you dont want to accidentally change while waiting for translations. When a
view is locked, you cant change some or all of its properties in the inspector or the project editor. You specify
the set of properties to lock by choosing a locking level, described in Locking level options.
Table 6-1
Locking levels
Locking level
Description
Nothing
All properties
Localizable properties
You cant change any user-visible strings and cant change a limited set
of other attributes, such as the views size. You can make other changes;
for example, you can change the enabled state of a control or cell.
Non-localizable properties
You can set the lock attribute for a single view or the entire nib file. By default, views inherit their lock attribute
from their parent view and top-level views inherit their lock attribute from the .storyboard or .xib file. If
you set a views lock attribute, it sets the lock attribute for all its descendant views.
To change the locking level of a view
1.
61
2.
In the Identity inspector (under the Document section), choose a locking level from the Lock pop-up menu.
Refer to Locking levels (page ?) for a description of the locking choices in this menu.
To obtain the lock value from its parent view, choose Inherited.
For example, choose Localizable Properties to continue developing your app while waiting for a nib or strings
file to be localized. Choose Non-localizable Properties if you are incorporating translations into a nib file and
dont want to make other changes inadvertently.
To change the locking level of the nib file
1.
2.
Choose a locking level from the Editor > Localization Locking menu.
Refer to Locking levels (page ?) for a description of the locking choices in this menu.
To unlock all the views in the file, choose Reset Locking Controls.
For example, to prevent any edits to the nib file that would impact localized strings files, choose Reset Locking
Controls followed by Localizable Properties.
Exporting Localizations
Export the development language resources to an XLIFF file and submit it to a localization team for translation
into multiple languages.
The first time you export localizations, only the base internationalizationthe .storyboard and .xib resource
filesexist in the project folder. Xcode generates the strings files from your project files and includes them in
the exported .xliff file. Xcode doesnt add the strings files to the project until you import localizations later.
The exported [Language ID].xliff file encodes the strings files in the standard XML Localization Interchange
File Format (XLIFF). (Most third-party localization tools support this XLIFF file format.) For example, if the
development language is English, the en.xliff file contains base internationalization strings files (one for
each .storyboard and .xib file), a Localizable.strings file, and an InfoPlist.strings file. The
source text in the strings files is in English.
62
Translators should return a separate .xliff file for each language. The files should use the language ID as
the prefix. For example, if you request en.xliff for English be translated into German and Russian, the
returned files should be named de.xliff for German and ru.xliff for Russian. The individual .xliff files
contain the actual translations.
The first step to localize your app is to export the development language or base localization for translation.
Before doing this, verify that the development language copyright notice in the Info.plist file is correct.
Xcode includes the human-readable copyright notice in the XLIFF file. For a complete list of the localizable
Info.plist keys, read Localizing the Information Property List Files (page 61).
To export the development language translation
1.
2.
3.
In the sheet that appears, enter a location in the Save As field and click Save.
Xcode saves the file to the location you specified with a .xliff extension. Xcode creates the folder (if it
doesnt exist) and places a file named [Language ID].xliff in the folder where Language ID is the
identifier for the development language. For example, if the development language is English, the filename
is en.xliff.
63
If you never added a language to your project, the export dialog appears similar to this screenshot:
The next time you export localizations, optionally export the development language resources, specific language
resources, or all language resources.
To export multiple localizations for translation
1.
2.
3.
64
If you added a language to your project, the export dialog appears similar to this screenshot:
4.
From the Include pop-up menu, choose Existing Translations or Development Language Only.
To export all or specific language resources, choose Existing Translations and then deselect the languages
that you dont want to include in the export in the Languages section below. To export the development
language resources, choose Development Language Only.
5.
Click Save.
For each language you select, Xcode saves an XLIFF file (a file with a language ID prefix and .xliff
extension) to the location you specified in the Save As field. For example, if you select German and French
from the language list, Xcode adds a de.xliff and fr.xliff file to the folder.
Importing Localizations
When you import localizations, Xcode adds the language and a set of localized strings files for the language
to the project. For example, if you import ru.xliff in the standard XML Localization Interchange File Format
(XLIFF) that includes the target language attribute, the Russian language is added to the project. The first time
you import localizations, the base internationalization files change to a group containing the strings files in
the project navigator. Xcode stores the language-specific strings files in language folders. For example, Xcode
creates a ru.lproj folder in the project folder and adds a localized copy of the Localizable.strings and
65
InfoPlist.strings files to the ru.lproj folder. The localized strings files are extracted from the
corresponding [Language ID].xliff file. The next time you import localizations, the strings files are merged
with your existing project files.
2.
3.
In the sheet that appears, select a file with a .xliff extension and click Open.
66
A sheet appears showing the differences between the imported XLIFF file and the existing resources in
the project folder.
4.
Click Import.
Xcode decodes the localized strings files from the XLIFF file and adds them to the project folder. Xcode
replaces existing strings files.
67
68
Select a strings file to view and optionally, edit the contents. The strings file contains key-value pairs that Xcode
automatically generates from the text it finds in the corresponding .storyboard or .xib file. If you use
NSLocalizedString macros in your code, as described in Separating User-Facing Text from Your Code (page
30), a Localizable.strings group also appears in the project navigator.
Another kind of strings file is InfoPlist.strings, which you use for localizing app properties that are visible
to users (such as the apps name). For the keys you can localize in an InfoPlist.strings file, read Localizing
the Information Property List Files (page 61).
The exported XLIFF files are placed in <dirpath>. Optionally, use the exportLanguage argument to export
other localizations.
69
To localize a resource
1.
2.
3.
4.
In the dialog that appears, choose a language from the pop-up menu and click the Localize button.
70
For example, choose Base if you want to use the resource file for all languages.
After localizing a resource, you can add it to additional languages using the File inspector.
To add localizations to a resource
1.
In the project navigator with the File inspector open, select the resource.
2.
In the Localization section, choose the additional languages you want to add.
Xcode duplicates the file in the corresponding language folder and it appears in the project navigator.
71
two categories, and others have three or more categories to represent quantities. If you display a formatted
string containing a variable quantity, you can use one string in your code that is localized using plural rules
specified in a .stringsdict file.
Similar to how you retrieve localized text from strings files, use NSLocalizedString macros in your code to
retrieve the format string for different plural forms from a .stringsdict file. Next, provide a localized
.stringsdict file for all the supported languages that have different plural rules. The NSLocalizedString
macros search an existing .stringsdict file before the associated strings file that has the same filename
prefix. For example, the macros search the Localizable.stringsdict file for the %d file(s) remaining
key first. If it is not found, the macros search the Localizable.strings file for the key. Therefore, only add
.stringsdict files for languages that have different plural rules.
To create language plural rules
1.
In your code, use a NSLocalizedString macro, passing a formatted string to retrieve a plural phrase.
For example, to display a variable number of files as text:
localizedString = [NSString
localizedStringWithFormat:NSLocalizedString(@"%d file(s) remaining",
@"Message shown for remaining files"), count];
To create the Localizable.strings file for each language, export and import localizations, as described
in Exporting Localizations (page 62) and Importing Localizations (page 65).
Xcode generates a Localizable.strings file from the NSLocalizedString macros in your code. For
example, this key-value pair appears in the development language Localizable.strings from the
previous code fragment:
/* Message shown for remaining files */
"%d file(s) remaining" = "%d file(s) remaining";
Alternatively, you can create the development language Localizable.strings file yourself, as described
in Creating Strings Files for User-Facing Text in Your Code (page 86).
3.
Create a .stringsdict property list file and localize it for each language that has different plural rules.
Add a property list file to the project (choose File > New > File and select Property List from the sheet). In
the project navigator, change the filename to Localizable.stringsdict and localize it in selected
languages, as described in Adding Additional Resources You Want to Localize (page 70).
4.
72
The .stringsdict file contains a collection of plural rules for each phrase. The top-level key is the same
key you pass to an NSLocalizedString macro in your code. The value for this key is a dictionary that
specifies the plural rule details. The dictionary contains the text to use for each number category. The
types of categories and meaning vary depending on the language.
For example, the English .stringsdict file for the %d file(s) remaining key is:
<plist version="1.0">
<dict>
<key>%d file(s) remaining</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@files@</string>
<key>files</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%d file remaining</string>
<key>other</key>
<string>%d files remaining</string>
</dict>
</dict>
</dict>
</plist>
In English, the one category is used for the number 1, and the other category is used for all other numbers
in English.
The Russian .stringsdict file for the %d file(s) remaining key is:
<plist version="1.0">
<dict>
<key>%d file(s) remaining</key>
<dict>
73
<key>NSStringLocalizedFormatKey</key>
<string>%#@files@</string>
<key>files</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string> %d </string>
<key>many</key>
<string> %d </string>
<key>other</key>
<string> %d </string>
</dict>
</dict>
</dict>
</plist>
5.
Example numbers
Localized string
one
1 file remaining
other
0, 2, 3,
2 files remaining
3 files remaining
For Russian, there are three possible categories with different formats:
Category
Example numbers
Localized string
one
1
21
74
Category
Example numbers
Localized string
many
0
20
other
2
22
For a complete description of the .stringsdict file properties, read Stringsdict File Format (page 97). For
the plural categories and rules for each language, see CLDR Language Plural Rules.
Video: WWDC 2013 Making Your App World-Ready: Localization > Using stringsdict
CFBundleDisplayName
CFBundleName
CFBundleShortVersionString
NSHumanReadableCopyright
For a complete description of the information property list, read Information Property List Key Reference .
75
For Mac apps, the user can rename the app in the Finder, so use the NSFileManager class to get the app
name:
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *appName = [[NSFileManager defaultManager] displayNameAtPath:bundlePath];
Adding Languages
Add languages to your project if you want to add language-specific resources, as described in Adding Additional
Resources You Want to Localize (page ?), before importing localizations. (Xcode automatically adds languages
to your project when importing localizations.) For example, add language-specific image and audio files to
your project or test language-specific plural rules before you begin localizing all the strings files.
When Xcode adds a language to your project, it creates a separate language folder to store the language-specific
resources. Xcode adds a strings file for each .storyboard and .xib file in the Base.lproj folder to the
language folder. The strings file has the same name as the .storyboard or .xib file but with the strings
extension. For example, if you have a storyboard named MyStoryboard.storyboard, the generated strings
file is named MyStoryboard.strings.
To add a language to a project
1.
In the project navigator, select the project (not a target) and click Info.
76
2.
In the Localizations section, click the Add button (+) under the Language column and choose the language
you want to add from the pop-up menu.
The menu items contain the language name followed by the language ID in parentheses, as in German
(de), Japanese (ja), and Arabic (ar). Menu items for scripts or dialects contain the region in parentheses, as
in German (Switzerland). The language ID for scripts or dialects uses subtags, as in pt-PT where pt is the
code for Portuguese and PT is the code for Portugal. For example, use pt as the language ID for Portuguese
as it is used in Brazil and pt-PT as the language ID for Portuguese as it is used in Portugal. The Other
submenu (at the bottom of the list) contains more languages and dialects.
These same language IDs are used in the names of the corresponding .lproj language folders, described
in Viewing Language Folders in Finder (page 60).
3.
In the dialog that appears, deselect the resource files you dont want to localize for this language.
77
For the file type Localizable Strings, Xcode creates a strings file for that resource. If you prefer to maintain
a separate .storyboard or .xib file for the language, choose the type of resource file from the File Types
pop-up menu insteadfor example, choose Interface Builder Cocoa Touch Storyboard for a Mac storyboard
file.
4.
78
Test your internationalized app during different stages of development, even before localizing your app.
Preview your app in Interface Builder to detect Auto Layout problems and non-localized strings, similarly run
your app using pseudolanguages, simulate right-to-left languages, and test specific languages and regions.
After importing localizations, test your app in all the languages you support.
In project navigator, select the .storyboard or .xib file you want to preview.
2.
3.
In the assistant editor jump bar, open the Assistant pop-up menu, scroll to and choose the Preview item,
and choose the .storyboard or .xib file from the submenu.
If a preview of the apps user interface doesnt appear in the assistant editor, select the window or view
you want to preview in the icon or outline view.
79
4.
In the assistant editor, choose the localization you want to preview from the language pop-up menu in
the lower-right corner.
A preview of the localization appears in the assistant editor. If you choose a real language, strings that do
not need to be localized or need to be localized, but currently are not, appear in uppercase.
If you detect that the strings files are out of sync with the base internationalization files (perhaps you made
changes to the user interface after importing localizations), export and import localizations again, as described
in Localizing Your App (page 60). You only need to translate the text that changed since the last time you
imported localizations. (Alternatively, read Updating Storyboard and Xib Strings Files Using ibtool for how to
update strings files after you make changes to the base internationalization .storyboard and .xib files.)
When previewing iOS apps, you can also change the iOS version, orientation, and form factor, as described in
Previewing Your Layout for Different Devices and Localizations.
Click the target in the Run destination menu and choose Edit Scheme.
2.
3.
To test Auto Layout, choose Double Length Pseudolanguage. All the localized strings appear duplicated,
changing the size and position of the views.
80
4.
5.
Click Run to launch your app in the pseudolanguage you specified in your scheme.
Alternative, to double the length of all the localized strings, add the NSDoubleLocalizedStrings launch
argument in the Arguments pane of the scheme editor or set the equivalent user default. For how to set the
right-to-left language launch arguments, read Testing Right-to-Left Languages.
81
Click the target in the Run destination menu and choose Edit Scheme.
2.
3.
4.
5.
Alternatively, add the NSShowNonLocalizedStrings launch argument. To identify stings that are not
localizable , add the NSShowNonLocalizableStrings launch argument in the Arguments pane of the scheme
editor or set the equivalent user default.
82
Click the target in the Run destination menu and choose Edit Scheme.
2.
3.
4.
5.
6.
Click Run to launch your app in the language and region you specified.
83
Alternatively, add AppleLanguages and AppleLocale launch arguments using the scheme editorfor
example, add -AppleLanguages "(de)" to specify the German language and -AppleLocale "fr_FR"
to specify the France region.
84
Follow the steps in this appendix if you want to generate and translate strings files stored in the project folder
yourself. In this case, you add the languages you want to support, generate the strings files, and localize the
strings files using AppleGlot glossaries or some other process. You are responsible for updating the strings
files when you change the user interface or add user-facing text to your code.
If you want to manage your own strings files, first add the languages you want to support to your project, as
described in Adding Languages (page 24).
Important: Alternatively, Xcode will automatically generate the strings files and add them to your project
if you export localizations, edit the XLIFF files (which contain the strings files), and import them, as described
in Localizing Your App (page 60).
85
For example, for a universal iOS app that uses English as the development language, the Base.lproj folder
contains Main_iPad.storyboard and Main.iPhone.storyboard, and the en.lproj folder contains
InfoPlist.strings. If you add the German language, Xcode creates a de.lproj folder containing a
InfoPlist.strings, Main_iPad.strings, and Main_iPhone.strings file. The files in the de.lproj
folder contain placeholder text that needs to be translated to German.
For a Mac app that uses English as the development language, the file structure may be similar to:
86
1.
Use the genstrings script to create the development language version of the Localizable.strings
file.
In Terminal, run these commands:
cd [Project folder]
find . -name \*.m | xargs genstrings -o .
For each occurrence of an NSLocalizedString macro in the source files, the script adds the comment
followed by the key-value pair (using placeholder text for the value) to the Localizable.strings file,
as in:
/* distance for a marathon */
"RunningDistance" = "RunningDistance";
If you use the NSLocalizedString macro in your code, the value for the key defaults to the key. If you
want different behavior, use one of the other NSLocalizedString macros that take more parameters,
described in Foundation Functions Reference .
2.
3.
In the ja.lproj/Localizable.strings file, enter the Japanese translation for the RunningDistance
key:
87
4.
";
Test your app in multiple languages, as described in Testing Your International App (page 79).
Incrementally test your app when making these types of changes to your code. Localize one set of language
files or use pseudolocalization techniques, described in Testing Using Pseudolocalizations (page 80).
The genstrings script also searches your code for user-facing text and adds it to a strings file, as described
in Using Strings Files for User-Facing Text (page 30). The file format is the same except your code provides
the comment for translators. To localize a strings file, instruct translators to replace the placeholder textthat
appears to the right of the equal sign below the commentwith localized text.
88
AppleGlot is a localization tool for iOS and Mac app developers. AppleGlot provides iOS and Mac language
glossaries to assist you in translating common text strings. It can also export user-facing text into standard
formats that localizers can easily translate into multiple languages. AppleGlot supports incremental development
so that you only need to translate the changes to user text with each release.
To download AppleGlot and the language glossaries, go to Build Apps for the World. Under Programming
Resources > Downloads, click AppleGlot and Localization Glossaries. If necessary, enter your Apple ID and
click Sign In. Download the DMG files for AppleGlot and the languages you support. To install AppleGlot, open
the AppleGlot DMG file and double-click AppleGlot.pkg.
Before you localize your files, you can translate all the common text strings using AppleGlot language glossaries.
To translate your .storyboard and .xib strings files using AppleGlot glossaries
1.
2.
For example, if the development language is English and the target is Russian, pass en for the
base_language_id and ru for target_langauge_id.
3.
In the Finder, paste the language resource folders into the AppleGlot environment _NewBase folder.
If you use base internationalization, paste the language-specific folder, [target_language_id].lproj,
into the _NewBase folder, and change the name of the folder to [base_language_id].lproj. For
example, paste ru.lproj into _NewBase, and change the name to en.lproj.
Otherwise, if you dont use base internationalization, the [base_language_id].lproj folder should
contain all the strings files that you want translated into the target language.
4.
Open the target language glossary DMG, and copy the glossaries (files with the lg extension) into the
_LanguageGlossaries folder.
5.
This creates a .ad file in the _ApplicationDictionaries folder with previously translated strings and
a .wg file in the _WorkGlossary folder that contains all the strings in your project with as much of the
translations from your Language Glossaries as possible.
89
6.
Optionally, localize the remaining strings in the files with the ad and wg extensions using a third-party
localization tool that supports these file formats.
7.
8.
In the Finder, paste the localized resources into your Xcode project folder.
Paste the contents of the _NewLoc/[base_language_id].lproj folder into your
[target_language_id].lproj folder in the Xcode project folder. For example, paste the contents of
the _NewLoc/en.lproj folder into the ru.lproj folder if the target language is Russian.
9.
To test the localization, launch your app using the target language, as described in Testing Specific
Languages and Locales in Xcode (page 83).
For Mac apps, the main menu items from an Xcode template appear translated except occurrences of the
app name.
For more information on AppleGlot, read the AppleGlot 4 Users Guide located in the AppleGlot DMG file.
90
Optionally, localize the changes in the output file before merging the changes with the [MyNib].strings file in
each lproj folder. To launch FileMerge from Xcode, choose Xcode > Open Developer Tool > FileMerge.
Alternatively, you can use the ibtool command to merge translations back into a nib file and perform other
incremental localization updates, as described in the ibtool man page. Or use the appleglot command to
manage changes to the strings files, as described in Localizing Text Using AppleGlot (page 65).
Creating a Pseudolocalization
If the pseudolocalization options, described in Testing Your Internationalized App (page 79), are not sufficient
to test your app, create your own pseudolocaliation. Add a language to your project, as described in Adding
Languages (page 24). Edit the strings files in the language folder by replacing the placeholder text with
pseudotext. Set the language launch argument, as described in Testing Specific Languages and Locales in
Xcode (page 83), and run your app.
For example, edit the placeholder text in a strings file by adding characteristics of world languages but keeping
the original text readable, as in:
/* distance for a marathon */
"RunningDistance" = "[]";
One technique is to add a prefix and suffix to each string. Then you can easily identify where these prefixes
and suffixes do not appear when testing your app. Use multibyte characters for prefixes to verify whether your
app supports such characters.
91
Language IDs identify a language, dialect, or script and are used to name language-specific resource folders
stored in the app bundle. Locale IDs identify a set of regional conventions and are used in APIssuch as the
NSLocale, NSDateFormatter, NSNumberFormatter, and NSCalendar classeswhere region information
is needed to format data. OS X and iOS use standard language ID and locale ID formats that consist of language
and region designators. For example, using a language combined with a region designator, a language ID can
distinguish between different languages and regional dialects.
Language Designators
A language designator is a code that represents a language. Use the two-letter ISO 639-1 standard (preferred)
or the three-letter ISO 639-2 standard. If an ISO 639-1 code is not available for a particular language, use the
ISO 639-2 code instead. For example, there is no ISO 639-1 code for the Hawaiian language, so use the ISO
639-2 code. Table B-1 lists language designators for a subset of languages.
Table B-1
Language
English
en
eng
French
fr
fre
German
de
ger
Japanese
ja
jpn
Hawaiian
no designator
haw
For a complete list of ISO 639-1 and ISO 639-2 codes, see ISO 639.2 Codes for the Representation of Names
and Languages.
92
Region Designators
A region designator is a code that represents a country. Use the ISO 3166-1 standard, a two-letter, capitalized
code shown in Table B-2.
Table B-2
Region
United States
US
United Kingdom
GB
Australian
AU
France
FR
Canadian
CA
For a complete list of ISO 3166-1 codes, see ISO 3166-1 Decoding Table.
Language IDs
A language ID identifies a language used in many regions, a dialect used in a specific region, or a script used
in multiple regions. To specify a language used in many regions, use a language designator by itself. To specify
a specific dialect, use a hyphen to combine a language designator with a region designator. To specify a script,
combine a language designator with a script designator. For example, to specify common English, use the en
language designator as the language ID. To specify the English language as it is used in the United Kingdom,
use en-GB as the language ID.
Table B-3 shows the supported language ID syntax and examples of common languages and dialects.
Table B-3
Language ID syntax
Examples
Description
[language designator]
en for English
Specifies a language
only.
fr for French
de for German
93
Language ID syntax
Examples
Description
[language
designator]-[region
designator]
Specifies a dialect of a
language.
Kingdom
fr-FR for French as used in France
fr-CA for French as used in Canada
de-AT for German as used in Austria
de-CH for German as used in Switzerland
[language
designator]-[script
designator]
Specifies a script of a
language.
For the script designator, use the ISO 15924 standard, four letters with the first letter uppercase and the last
three lowercase, as shown in Table B-4.
Table B-4
Script language ID
Description
az-Arab
az-Cyrl
az-Latn
sr-Cyrl
sr-Latn
uz-Cyrl
uz-Latn
zh-Hans
zh-Hant
94
See the ISO 639-3 and Macro Languages section of Understanding the New Language Tags for more Chinese
language ID examples. For the complete BCP 47 specification for language tags, go to BCP 47: Tags for Identifying Languages. However, iOS and OS X only support the language ID syntax consisting of a language designator
and optional region or script designator.
Locale IDs
A locale ID identifies a specific region and its cultural conventionssuch as the formatting of dates, times,
and numbers. To specify a locale, use an underscore character to combine a language ID with a region designator,
as shown in Table B-5. For example, the locale ID for English-language speakers in the United Kingdom is
en_GB, while the locale for English-speaking residents of the United States is en_US.
Table B-5
Locale ID syntax
Examples
Description
[language designator]
en
fr
[language designator]_[region
designator]
en_GB
[language designator]-[script
designator]
az-Arab
[language designator]-[script
designator]_[region designator]
zh-Hans_HK
zh_HK
zh-Hans
Only use a script designator in a locale ID when there is ambiguity. For example, because Traditional Chinese
is the default language in Hong Kong, use zh_HK, where zh is the code for Traditional Chinese and HK is the
code for the Hong Kong region. For Simplified Chinese used in Hong Kong, use zh-Hans_HK as the locale ID,
where zh-Hans is the code for the Simplified Chinese script.
95
If you choose to create a new designator, be sure to follow the rules found in sections 2.2.1 and 4.5 of BCP 47:
Tags for Identifying Languages. Tags that do not follow these conventions are not guaranteed to work. When
using subtags, ensure that the abbreviation stored by the users language settings matches the designator
used by your .lproj directory exactly.
96
</dict>
<key>%d service hour(s)</key>
<dict>
</dict>
<key>%d award(s)</key>
<dict>
</dict>
</dict>
</plist>
You pass the same stringsfor example, @%d file(s) remaining, @%d service hour(s) and @%d
award(s)to a NSLocalizedString macro in your code.
97
A format string that contains variables. A variable is preceded by the %#@ characters and followed by the
@ character, as in:
<key>NSStringLocalizedFormatKey</key>
<string>%#@files@</string>
where the variable name is files. The format string can contain multiple variables, as in %#@files@
(%#@bytes@, %#@minutes@).
[variable]
A dictionary of key-value pairs specifying the rule to use for [variable], as in:
<key>files</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%d file remaining</string>
<key>other</key>
<string>%d files remaining</string>
</dict>
For example, if the number is 2, the @%d files remaining format string is returned and the localized
string becomes @2 files remaining.
Add plural rules for each variable that appears in the NSStringLocalizedFormatKey format string.
98
NSStringFormatSpecTypeKey
Specifies the type of language rule. The only possible value is NSStringPluralRuleType, which
indicates a language plural rule.
NSStringFormatValueTypeKey
A string format specifier for a number, as in %d for an integer. For a list of format specifiers, see String
Format Specifiers in String Programming Guide .
zero
The format string to use for all numbers not covered by the other categories. This key is required.
The meaning of the categories is language-dependent and not all languages have the same categories.
For example, English only uses the one, and other categories to represent plural forms. Arabic has different
plural forms for the zero, one, two, few, many, and other categories. Although Russian also uses the
many category, the rules for which numbers are in the many category are not the same as the Arabic rules.
Using the NSStringFormatValueTypeKey format specifier in the zero, one, two, few, many, and other
format strings is optional.
For example, the one format string can be One file remaining while the other format string can be
%d files remaining for English.
Use the format specifier or spell out numbers in the format strings.
If you use a numeric in the format string, as in 1 file remaining for English, it may not be localized
when the user changes the region (for example, if the number set changes). Instead, use the format
specifier, as in %d file remaining; otherwise, spell out the number, as in One file remaining.
For the plural categories and rules for each language, see CLDR Language Plural Rules.
99
Date
Notes
2015-01-12
2014-10-16
2014-09-17
100
Glossary
101
Apple Inc.
Copyright 2015 Apple Inc.
All rights reserved.
No part of this publication may be reproduced,
stored in a retrieval system, or transmitted, in any
form or by any means, mechanical, electronic,
photocopying, recording, or otherwise, without
prior written permission of Apple Inc., with the
following exceptions: Any person is hereby
authorized to store documentation on a single
computer or device for personal use only and to
print copies of documentation for personal use
provided that the documentation contains
Apples copyright notice.
No licenses, express or implied, are granted with
respect to any of the technology described in this
document. Apple retains all intellectual property
rights associated with the technology described
in this document. This document is intended to
assist application developers to develop
applications only for Apple-branded products.
Apple Inc.
1 Infinite Loop
Cupertino, CA 95014
408-996-1010
Apple, the Apple logo, Cocoa, Cocoa Touch,
Finder, iPad, iPhone, iTunes, Mac, Numbers,
Objective-C, OS X, and Xcode are trademarks of
Apple Inc., registered in the U.S. and other
countries.
App Store and Mac App Store are service marks
of Apple Inc.
IOS is a trademark or registered trademark of
Cisco in the U.S. and other countries and is used
under license.
Times is a registered trademark of Heidelberger
Druckmaschinen AG, available from Linotype
Library GmbH.
APPLE MAKES NO WARRANTY OR REPRESENTATION,
EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS
DOCUMENT, ITS QUALITY, ACCURACY,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR
PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED
AS IS, AND YOU, THE READER, ARE ASSUMING THE
ENTIRE RISK AS TO ITS QUALITY AND ACCURACY.
IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES RESULTING FROM ANY DEFECT, ERROR OR
INACCURACY IN THIS DOCUMENT, even if advised of
the possibility of such damages.
Some jurisdictions do not allow the exclusion of
implied warranties or liability, so the above exclusion
may not apply to you.