Plug'n'Play gradle plugin for your Android projects to convert between Android strings.xml translations and Excel.
Useful if your translations are created by non-technical/external translators who prefer to use Excel/LibreOffice.
- Export from Android project's
strings.xmlfiles to a single, formatted, reproducible Excel file (.xlsx) - Import
strings.xmlfiles from given Excel file into correspondingvaluessubfolders - Supports Android quantity strings (plurals)
- Correctly escapes/unescapes special characters + HTML tags in
strings.xmland Excel - User-Friendly Excel sheet formatting including highlight missing translations, useful auto-filters and comments
- Auto-Sorts the translations by their key
In build.gradle:
plugins {
id("io.github.philkes.android-translations-converter") version "1.0.5"
}Run ./gradlew exportTranslationsToExcel
Optional configuration in build.gradle (shown values are the defaults):
tasks.named("exportTranslationsToExcel", ExportToExcelTask) {
/**
* Input path which contains 'strings.xml' (or in subfolders)
*/
inputDirectory = project.file("app/src/main/res")
/**
* Exported Excel file path (.xlsx)
*/
outputFile = project.file("translations.xlsx")
/**
* Whether the exported Excel sheet should be formatted to make it more user-friendly.
*/
formatExcel = true
}To preview a full exported Excel file download it here
Android supports quantity strings (plurals).
To support these plurals, for every <plurals> in the strings.xml there are multiple for all the supported quantities.
The keys for these plurals have appended _PLURALS_{QUANTITY} to differentiate them. There is always a row for every possible quantity, doesn't matter if there is an existing translation in a language or not. If the default language does not specify a translations for a certain quantity, this row is highlighted in yellow with a corresponding comment.
Run ./gradlew importTranslationsFromExcel
Optional configuration in build.gradle (shown values are the defaults):
tasks.named("importTranslationsFromExcel", ImportFromExcelTask) {
/**
* Input Excel File containing translations.
*/
inputFile = project.file("translations.xlsx")
/**
* Folder to import into.
* For every folder-name/language a subfolder will be created and its corresponding `strings.xml` generated.
*/
outputFile = project.file("src/main/res/")
}To preview the output see app/src/main/res folder
The exportTranslationsToExcel can easily be automated, in order to always have the exported translation.xlsx up-to-date with the Android translations.
This can be done either via a pre-commit hook or by simply executing it on every build.
Note that exportTranslationsToExcel execution is skipped if none of the strings.xml files contents have changed since the last execution.
In build.gradle:
preBuild.dependsOn exportTranslationsToExcel- Copy pre-commit folder to the root of your project
- In
build.gradle:tasks.register('installLocalGitHooks', Copy) { def scriptsDir = new File(rootProject.rootDir, 'scripts/') def hooksDir = new File(rootProject.rootDir, '.git/hooks') from(scriptsDir) { include 'pre-commit', 'pre-commit.bat' } into { hooksDir } inputs.files(file("${scriptsDir}/pre-commit"), file("${scriptsDir}/pre-commit.bat")) outputs.dir(hooksDir) fileMode 0775 } preBuild.dependsOn installLocalGitHooks
- Whenever you commit your changes the exported Excel will be kept up-to-date
