Τετάρτη, 15 Μαΐου 2013

LOCALIZATION - an ios application

apple instructions here

Below is instrunctions from the book The Big Nerd Ranch Guide (3rd Edition)


Internationalization Using NSLocale:

NSString * currencySymbol = [[NSLocale currentLocale] objectForKey: NSLocaleCurrencySymbol];
[ aLabel setText: [NSString stringWithFormat:@"%@", currencySymbol]];

Localizing Resources: 

  • These resources are organized into language-specific directories, known as lproj directories
  • add a language in the project setting first!
  • Click on an .xib file
  • open the file inspector
  • find the section Localization and click the + button at the bottom.  (this creates an lang.lproj folder and adds a copy of aaa.xib to it. 
  • Tsanslate localized files yourself!
  • Instead! you can use a command-line tool named ibtool to get the strings from your native language XIB file into a file. Then, you can trasnlate thses strings and create a new XIB file for each language. 
    • open terminal.app (Applications/Uitilites)
    • cd (Drag the en.lproj folder's icon from the Finder onto the Terminal window)
    • cd /iphone/myappication/application/en.lproj
    • ibtool --export-strings-file ~/Desktop/MyViewController.strings MyViewController.xib (this will create a DetailViewController.strings files on your desktop that contains all of the strings in your XIB file. 
    • open the file , transalate the texts to greek version. Save this new greek file. 
    • In terminal enter: ibtool --import-strings-file ~/Desktop/MyViewController.strings --write
    • ibtool --import-strings-file ~/Desktop/MyViewController.strings --write /iphone/myappication/application/gr.lproj/MyViewControoler.xib /iphone/myappication/application/en.lproj/MyViewControoler.xib
    • This command says Create MyViewController.xib in gr.lproj from MyViewController.xib in en.lproj, and then replace all of the strings with the values from MyViewController.strings.
    • Ingore the warnings from ibtools about GSCapabilities. 
    • Open the MyViewController.xib (greek) in Xcode. This XIB file is now localized to Greek. 

To test DELETE the application from your device or simulator. Then choose Clean, Build.
Change the language settings on the device (example to Greece) to see the effect. 

NSLocalizedString and Strings Tables
Fast review: 

  • Replace the strings you want to be transalate with NSString *translatedString = NSLocalizedString (@"Hello!", @"The greeting for the user");
  • At terminal run genstrings MyViewController.m to extract the above strings
  • with mouse put the Localizable.strings into your project
  • Localize from file inspector teh Localizable.strings. Add you langs also. 
  • click on lang version of Localizable.string you prefer and change the strings after the = into your lang.
  • clean - build - fun. 
Analytical:
For dynamically created NSStrings instances you must create a strings table. A strings table is a file containing a list of key-value pairs for all of the strings that your application uses and their associated translations. It's a resource file that you add to your application,.
Whenever you have a string in your code like @"My text", to internationalize this, replace literal strings with the function NSLocalizedString
NSString *translatedString = NSLocalizedString (@"Hello!", @"The greeting for the user");

Once you have a file that has been internationalized with the NSLocalizedString function,  you can generate strings tables with a command-line application. 
Open Terminal.app and navigate to the location of MyViewController.m The command will look like this: 
  • cd /iphone/Myapplication/Myapplication/
  • genstrings MyViewController.m
This creates a file named Localizable.strings in the same directory as MyViewController.m Drag this file into the project navigator. When the application is compiled, this resource will be copied into the  main bundle. 

Open the Localizable.strings file inn the editor area (reinterpet in Unicode (UTF-16)-utilitie-file inspector Text Settings - Text Encoding - Unicode )) if any problem. 
Now localize ti like the above XIB file in the first section of this post. Select the file in the project navigator an dclick the plus button in the utilities area. Add the Greek localization and then open the Greek version of Localizable.strings.  The string on the lefthand side is the key that is  passed to the NSLocalizedString function and the string on the righthand side is what is returned. Change the text as you want. 

build and run.  (better first delete the application, clean your project and rebuild. 

1 σχόλιο:

  1. Hi!
    If you’re interested in a tool to collaboratively localize iOS apps for iPad or iPhone, I suggest you give https://poeditor.com/ a shot. It’s a very user-friendly online translation platform that handles .strings files too, along with other popular language file formats. You’ll see that it has a sum of very useful features to aid your localization workflow, like set reference language and translation memory. Cheers and good luck with your projects!

    ΑπάντησηΔιαγραφή