internationalization of an iPhone Application

前端 未结 4 1913
夕颜
夕颜 2021-01-27 10:45

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 trans

相关标签:
4条回答
  • 2021-01-27 10:51

    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.

    0 讨论(0)
  • 2021-01-27 11:05

    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.

    0 讨论(0)
  • 2021-01-27 11:15

    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!

    0 讨论(0)
  • 2021-01-27 11:15

    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.).

    0 讨论(0)
提交回复
热议问题