Get Localization специально разработан для перевода строк и файлов XLIFF.
Get Localization supports both strings files and also XLIFF file format that was recently added to Xcode. We recommend using XLIFF as it's easy for the developer and can be exported and imported by Xcode. This document covers all Apple operating systems: iOS, Mac OS X, watchOS and tvOS.
This guide is divided into three sections: Internalization, Set up your Get Localization project and Managing resource files. Internalization explains how you separate your strings to resource files using Xcode. Then you will learn how to set up a Get Localization project for your app. Managing resource files section will explain steps to export and import XLIFF files from Xcode and to create a Continuous Localization process for your app.
Software Internationalization is a process to separate content from code so that it can be localized. If you're unfamiliar with the concept, please read our blog post Software Internationalization for Dummies for starters.
Foundation Framework provides a way to separate your textual content from code to resource files. These resource files are much easier to translate than actual code. When you wrap your NSString with NSLocalizedString method, the framework will identify the string as a translatable string and export it automatically to the resource file.
NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"Buy this item for %@", @"Contextual comment for translator e.g. this is a IAP item, placeholder is for price e.g. $1.99"), self.price];
This requires that you define the xibs and storyboards which you want to localize.
First select your storyboard or xib file. Then locate the document icon in File Inspector and the Localization subsection. Then Click Localize.
Confirm that you want to localize this file. We recommend using Base localization system so make sure Base is selected. As a result, you should see something like this:
Next you need to select the languages you wish to translate to. Navigate to your project settings:
Click the plus icon and select the languages.
Next select all the xib and storyboard files you wish to localize into this language.
And click Finish. Now all the selected files are ready for localization.
Next you need a Get Localization Workspace for your app. Sign up and create a new Workspace here. Remember your Workspace name as you will need it later.
You have two options, either export (and import) the XLIFF files using the UI or command-line. We recommend building a script that automates this process, it will make translation updates convenient in the future when you update your app. We call this a continuous localization process. However, here's a brief introduction to you can export and improve from Xcode's user interface.
Step 1: Click your project settings
Step 2: To export, simply click Editor → Export For Localization. Note that this option is visible only when you select the project. Then select where you want to export your XLIFF file. This file is called Master file and is used as a source for translations.
Step 3: To import, click Editor → Import Localization. Select all the translated XLIFF files you have downloaded from Get Localization. Xcode will take care of the rest.
Continuous localization means that the process is automated. I.e. when you update your app, you can run a simple script that uploads your updated content to the Get Localization server for translation and updates the latest translations back to your app. We provide a simple command-line tool that makes this easy for you. Here are the steps to initialize your project, push the files for translation and pull the translations back to your application.
Install the Get Localization Command-Line Tool
sudo pip install gl
Then initialize the project
cd my/project/root/ gl init [workspacename]
workspacename is the Workspace you created in Get Localization. Your project root is typically the same dir where you have cloned your git/hg repository.
Export XLIFF using Xcode command-line tools
xcodebuild -exportLocalizations -localizationPath i18n_files/ -project [xcodeprojectname]
xcodeprojectname is the name of your project in Xcode. localizationPath is the path where the en.xliff is exported, in this case it's i18n_files.
Add your exported XLIFF file to the Get Localization repository
gl add i18n_files/en.xliff
This is something you need to do only once. glcli is now tracking the file automatically.
Push your file(s) to Get Localization server
Now your file is ready for translation and you can proceed to your Get Localization project. Simply add the languages you wish to translate your app into and click Order translations.
Configuring translation pull
Next you need to map the translation files so that they are placed correctly on your local file system (note that you need some translations already in the system). First check the status of your project.
This returns the status of your translations and also the corresponding language code. Let's assume that you have a French project and the language code is 'fr':
gl map-locale i18n-files/en.xliff fr i18n-files/fr.xliff
This basically means that the French translation of the file i18n-files/en.xliff is saved as i18n-files/fr.xliff. This information is saved to your local repository, you only need to do this once. Simply repeat this command for all your language projects.
Pull translations from server
Import translations with Xcode
Unfortunately Apple does not provide a way to do this from command-line, so you need to import the XLIFF files from Xcode UI.
To import, simply click Editor → Import Localization. Select all the translated XLIFF files from i18n-files directory and Xcode will take care of the rest.
After setup, you push the translations to server with gl push command, and pull the translations back with gl pull command. Your continuous localization script could look something like this:
gl pull xcodebuild -exportLocalizations -localizationPath i18n_files/ -project [xcodeprojectname] gl pushIt's recommended to pull the current translations before updating the new master file as processing takes some time.