user1051935
user1051935

Reputation: 589

internationalization of an iPhone Application

I am new to iPhone App development (I am using XCode 4.2) and I was wondering if there is a way to translate all the strings , caption etc ... internally without having to translate them one by one .

an idea I have in mind is to use NSUserDefaults to save the language as a global variable and translate everything accordingly

another option is to make a look up table (is it even possible in Objective-C ?)

Thanks

Upvotes: 0

Views: 684

Answers (4)

Oscar Gomez
Oscar Gomez

Reputation: 18488

All you will have to create are the files with the key-value pairs for each language you want to translate and name them accordingly i.e. _en, _fr and so on.

Then all you have to do is send a message to this method:

NSLocalizedString(@"myKey", nil)

And this will return the localized String, in whatever language the current iPhone configuration is.

Upvotes: 0

Localizer
Localizer

Reputation: 441

You can read a step-by-step tutorial of the process here:

iPhone Localization Tutorial

Here's a high-level overview of the basics (the above tutorial has details):

1) Change all your coded strings to call: NSLocalizedString(@"My text", @"Context for the translator")

2) Export all your strings using the genstrings Terminal command.

3) This creates a text file called Localizable.strings with all your English (source) strings. It looks like this:

/* Context for the translator */
"My text" = "My text";

You send that file to the translators. They'll translate the right side like this: "My text" = "Mi texto";

4) You place each translated Localizable.strings file in its proper language folder: en.lproj, fr.lproj, es.lproj, etc.

When your app loads on the iPhone it will check the user's language settings. If the user has chosen French as the system language, the Localizable.strings inside your fr.lproj folder file will load. If there are any untranslated strings, it just defaults to English (or whatever your source language is) for those.

It's worth following the whole tutorial and note that the file/folder names have to be exact!

Upvotes: 1

Felix Lamouroux
Felix Lamouroux

Reputation: 7484

You can use NSLocalizedString(@"<#key#>", @"<#comment#>") and one file (named Localizable.strings( per language. If you use the above function you can use the App Linguan (available on the Mac App Store) to generate the Localizable.strings files.

There is also a command line tool called genstrings that will create the file for you, but believe me that Linguan app will pay for itself in minutes.

You should always add a comment to allow a better translation and to provide context about the key.

Upvotes: 1

David Dunham
David Dunham

Reputation: 8329

Look up the documentation for NSLocalizedString. And how to localize your .xib files (you make localized copies in English.lproj, de.lproj, fr.lproj, etc.).

Upvotes: 0

Related Questions