Python 2.7 or preferably Python 3 must be installed on your machine with the pip command also available.
Clone the repository and run pip install -r requirements.txt.
gslocalization with Google Sheetsservice account key JSON file from your Google Developer Console
Google Drive API and Google Sheets API are enabledCredentials and from the Create credentials menu, select Service account keyApp Engine Admin role)JSON is selected in the Key type options.CreateJSON file will begin downloading. Save this file and use it later for authentication.python ios-gslocalization.py -x {PATH_TO_XCODEPROJ} -o {XLIFF_OUTPUT_DIR} -a {JSON_AUTH_FILE_PATH} -e {SHARE_EMAIL_ADDRESS} -l {LOCALIZATION_LANGUAGES} -d {DEV_LANGUAGE}
PATH_TO_XCODEPROJ - path to your .xcodeproj file
xcodebuild (exporting and importing localizations)XLIFF_OUTPUT_DIRXLIFF_OUTPUT_DIR - output directory for the generated XLIFF filesJSON_AUTH_FILE_PATH - path to the Google Sheets Service account keySHARE_EMAIL_ADDRESS - the email address to share the created spreadsheets
Service account key, all the spreadsheets are created and owned by the service account (ex. [email protected])LOCALIZATION_LANGUAGES - a string containing multiple language codes used for localization
DEV_LANGUAGE (optional, defaults to en) - the language code for the project's developent languageThis script exports the current localizations for your project using xcodebuild.
It parses the obtained XLIFF files and uploads them to Google Sheets.
There is one spreadsheet for every language, with the following name format: {PROJECT_NAME}_{LANGUAGE_NAME}_localizations (ex. MyProject_Spanish_localizations, MyProject_Russian_localizations, etc.). Inside each spreadsheet, there is one worksheet per platform (ex. ios_strings, android_strings). The {PROJECT_NAME} is inferred from the xcodeproj filename.
All the strings are added to their corresponding spreadsheet, with the following header:
Source: SOURCE_LANGUAGE | Target: TARGET_LANGUAGE | Example | Comment | String Key | File Path
Source: SOURCE_LANGUAGE = text in the source languageTarget: TARGET_LANGUAGE = text translated in the target languageExample = empty if the string contains placeholders (%@, %d, etc.). This is a place to provide an example for translators.Comment = NSLocalisedString commentsString Key = the ID of the stringFile Path = relative path to the source file of the string (.strings file or .storyboard)After updating the translation in Google Sheets, run the same script again to import the new strings into your XCode project.
python android-gslocalization.py -p {PROJECT_NAME} -r {PATH_TO_RES_FOLDER} -a {JSON_AUTH_FILE_PATH} -e {SHARE_EMAIL_ADDRESS} -l {DEVELOPMENT_LANGUAGE}
PROJECT_NAME - project name (used to prefix the spreadsheet name)PATH_TO_RES_FOLDER - path to your Android res folder
strings.xml filesstrings.xml file, the target language is detected by the parrent folder name (ex. values-es for Spanish)JSON_AUTH_FILE_PATH - path to the Google Sheets Service account keySHARE_EMAIL_ADDRESS - the email address to share the created spreadsheets
Service account key, all the spreadsheets are created and owned by the service account (ex. [email protected])DEVELOPMENT_LANGUAGE - the language code of your development language (default = en)This script loads all the strings.xml files inside PATH_TO_RES_FOLDER.
It parses the obtained XML files and uploads them to Google Sheets.
There is one spreadsheet for every language, with the following name format: {PROJECT_NAME}_{LANGUAGE_NAME}_localizations (ex. MyProject_Spanish_localizations, MyProject_Russian_localizations, etc.). Inside each spreadsheet, there is one worksheet per platform (ex. ios_strings, android_strings).
All the strings are added to their corresponding spreadsheet, with the following header:
Source: SOURCE_LANGUAGE | Target: TARGET_LANGUAGE | String ID
Source: SOURCE_LANGUAGE = text in the source languageTarget: TARGET_LANGUAGE = text translated in the target languageString ID = the ID of the stringAfter updating the translation in Google Sheets, run the same script again to overwrite the strings.xml files in your resources folder.
# parsing arguments
argparse
# provides access to Google Sheets API
pygsheets
# XML parsing for XML/XLIFF files
lxml
# type hinting
typing
# colored output in consolde
colorama
# conversion between language code and language name
langcodes; python_version>'3'
langcodes-py2; python_version<'3'
Objective C, use NSLocalizedStringWithDefaultValue(@"KEY", nil, [NSBundle mainBundle], @"DEFAULT_VALUE", @"COMMENT")] instead of NSLocalizedString(@"KEY", @"COMMENT")]Swift, use NSLocalizedString("KEY", tableName: nil, bundle: Bundle.main, value: "DEFAULT_VALUE", comment: "COMMENT") instead of NSLocalizedString("KEY", comment: "COMMENT")NSLocalizedString calls to include a default value