Internationalize
the app for English, Spanish, and Arabic.
The
International
Organization for Standardization
(ISO)
has two-letter codes
(ISO 639–1)
for the natural languages:
EN
,
ES
,
AR
.
(The above Arabic is pronounced “Ahalan bil-Alam!”
I went to the
Hello, World!
page in Wikipedia
and clicked on
Arabic in the left panel.
It’s right above Azərbaycanca.)
Hello
folder that contains the
Hello, World!
project,
create subfolders named
en.lproj
,
es.lproj
,
ar.lproj
.
Open the
Hello
folder,
control-click under the last item,
and select
New Folder
.TextEdit.app
to create a file named
Localizable.strings
.
The
Localizable.strings
in
en.lproj
will contain the following line.
"Greeting" = "Hello, World!"; /* Don't forget the semicolon. */After you have typed this file into
TextEdit.app
,
save it with the following commands.
Format → Make Plain Text
Convert this document to plain text? OK
File → Save As…
Save As: Localizable.strings
Plain Text Encoding: Unicode (UTF-16)
Save
You have used the extension ".strings" at the end
of the name. The standard extension is ".txt". Use strings.
en.lproj
folder and make sure you saved the file as
Localizable.strings
,
not as
Localizable.txt
.
Localizable.strings
es.lproj
will contain
"Greeting" = "¡Hola, Mundo!";
To get the upside down exclamation point ¡,
Edit → Special Characters…
View: Roman
By Category
Punctuation
Localizable.strings
ar.lproj
will contain
"Greeting" = "!أهﻼ بالعالم";
Localizable.strings
drawRect:
method of class
View
,
change
NSString *string = @"Hello, World!";to
NSString *string = NSLocalizedString(@"Greeting", @"displayed with drawAtPoint:");
Settings
app.
Settings →
General →
International →
Language →
Español
Done
Settings →
General →
International →
Region Format →
Spanish → Spain
Done
The name of the app is listed in the
Hello-Info.plist
file.
Strings in this file have to be internationalized in a different way.
Open the
Hello-Info.plist
file in the
Supporting Files folder of the Xcode Project Navigator.
One of the keys has the user-friendly name
Bundle display name
.
To see the real name of this key,
control-click on the name and select
Show Raw Keys/Values
.
Note that the name of the key changes to the single word
CFBundleDisplayName
.
To change it back, unselect
Show Raw Keys/Values
.
InfoPlist.strings
in the folders
en.lproj
,es.lproj
,ar.lproj
.CFBundleDisplayName = "Hello, World!";
CFBundleDisplayName = "¡Hola, Mundo!";
CFBundleDisplayName = "!أهﻼ بالعالم";
InfoPlist.strings
Localizable.strings
files to
"Greeting" = "Wait %d minutes.";
"Greeting" = "Espere %d minutos.";
"Greeting" = "دقائق %d انتظري";
For the
%d
,
see the
list
of formats.
In the
drawRect:
method of class
View
,
change the
string
to
int n = 5; //minutes NSString *format = NSLocalizedString(@"Greeting", @"displayed with drawAtPoint:"); NSString *string = [NSString stringWithFormat: format, n];See Formatting String Resources.