Learn how to localize your Android app with SimpleLocalize
using translations in strings.xml files.
This guide will help you to get started with SimpleLocalize and translation editor in a few minutes.
Installation
SimpleLocalize CLI is a command line tool that helps you to integrate localization into your development workflow. It can be used to upload and download translations from SimpleLocalize.
curl -s https://get.simplelocalize.io/2.12/install | bash. { iwr -useb https://get.simplelocalize.io/2.12/install-windows } | iex;npm install @simplelocalize/cliThe @simplelocalize/cli package downloads the CLI binary for your system. Source code is available in the GitHub repository.
Upload source translations
In this step, you will upload your strings.xml files to SimpleLocalize.
Thanks to the command-line tool, you can upload multiple files at once from any directory.
simplelocalize upload \
--apiKey YOUR_API_KEY \
--uploadPath ./resources/values-{lang}/strings.xml \
--uploadFormat android-stringsYou may also want to upload only one file for a specific language. To do that, you can use the --languageKey option with
the language key from the Languages tab.
$ simplelocalize upload \
--apiKey YOUR_API_KEY \
--languageKey en \
--uploadFormat android-strings \
--uploadPath ./values/strings.xml
Extract translation keys (optional)
If you don't have translation keys in your strings.xml files,
you can use the extract command to generate them automatically.
CLI can find translation key usages in .java and .kt files.
Translation keys will
be automatically uploaded to the translation editor.
$ simplelocalize extract \
--apiKey YOUR_API_KEY \
--projectType google/android \
--searchDir ./srcTranslate your Android app
Now you can translate your Android application strings using the translation editor and save changes.
If you want to translate your app in multiple languages fast, you can add new languages in the Languages tab and use the auto-translation feature to speed up the process.
Download translations
Once you finish the translation, you can download the translated strings.xml files using the download command.
CLI will download the files to the resources/values-{lang}/strings.xml files,
where {lang} is the language code set in Languages tab.
simplelocalize download \
--apiKey YOUR_API_KEY \
--downloadFormat android-strings \
--downloadPath ./resources/values-{lang}/strings.xmlMapping for default values directory
If you would like to support the strings.xml translations in default ./resources/values/strings.xml directory, you can use the mappings.lang field in the configuration file:
# simplelocalize.yaml
mappings:
lang:
- languageKey: "en"
placeholder: ""
- languageKey: "fr"
placeholder: "-fr"
- languageKey: "de"
placeholder: "-de"
- languageKey: "pl"
placeholder: "-pl"
and adjust the downloadPath and uploadPath with:
./resources/values{lang}/strings.xml # removed '-'
Now, the default translations will be placed in resources/values/strings.xml file, and the other translations will be placed in resources/values-{lang}/strings.xml.
./res/values/strings.xml
./res/values-fr/strings.xml
./res/values-de/strings.xml
./res/values-pl/strings.xml
Sync translations with GitHub App
Instead of running the CLI, you can connect your repository with SimpleLocalize GitHub App
to upload strings.xml files on every push and get translated files back in a pull request.
Add simplelocalize-github.yml to the root of your repository and use language-paths for the default values directory:
# simplelocalize-github.yml
upload:
files:
- path: "app/src/main/res/values-{lang}/strings.xml"
format: "android-strings"
options:
- "UPDATE_TRANSLATIONS"
language-paths:
en: "app/src/main/res/values/strings.xml"
download:
files:
- path: "app/src/main/res/values-{lang}/strings.xml"
format: "android-strings"
language-paths:
en: "app/src/main/res/values/strings.xml"
Add a language-paths entry for every language whose directory name differs from its language key in SimpleLocalize,
e.g., pt-BR: "app/src/main/res/values-pt-rBR/strings.xml". Learn more about language-specific paths.