The androidI18n gradle plugin automaticallly generates strings.xml
resources files from a given translations (i18n) source file.
The plugin provides the following gradle tasks:
-
androidI18nImport
: imports the i18n translations from the source file and generates the android resources for each supported locale:values/strings.xml
values-fr/strings.xml
values-es/strings.xml
-
androidI18nExport
: export the android resources for all locales to a XLSX file in thebuild
directory of the current module. The path of the generated XLSX file is displayed in the build output:./gradlew app:androidI18nExport [...] > Task :app:androidI18nExport Resources were exported to: /path/to/app/build/i18n.xlsx [...]
Follow the instructions described here.
Simply add this configuration block to your build.gradle
file:
androidI18n {
// Source file containing i18n translations.
sourceFile = '/path/to/source/file.xls'
// Default android locale corresponding to 'values' directory.
defaultLocale = 'fr'
}
An empty (or blank) sourceFile
simply disabled plugin execution (convenient for Continuous Integration).
When applied to the configuration of a single module eg app
, the plugin operates in single module mode.
In this mode, the export task androidI18nExport
will create an Excel spreadsheet with one sheet named android-i18n
that contains all translation keys and the corresponding texts for each language.
The import task androidI18nImport
will take an Excel spreadsheet and generate a single set of strings.xml
files (one file by language) into the directory structure of the single module.
When applied to a project with several child modules, the plugin operates in the multi module mode.
In this mode, the export task androidI18nExport
will create an Excel spreadsheet with several sheets named after the child modules. Each sheet corresponds to a child module and contains all the translation keys of this module and the corresponding texts for each language.
The import task androidI18nImport
will take an Excel spreadsheet and generate several sets of strings.xml
files (one set by module, then one file by language) into the directory structure of each child module.
Pattern: smb://<domain>;<login>:<password>@<host>/<path_to_file>
The plugin uses jcifs to establish a connection with the remote samba URI.
Jcifs client properties can be provided
through gradle project properties using prefix androidI18n.*
:
androidI18n.jcifs.smb.client.dfs.disabled=true
androidI18n.jcifs.smb.client.responseTimeout=5000
Pattern: \\<host>\<path_to_file>
For the moment, the plugin only supports .xls
and .xlsx
source file types. Files must respect following structure:
key | fr | en | es |
---|---|---|---|
home_text_1 | Bonjour le monde ! | Hello world! | ¡Hola Mundo! |
home_text_2 | Avec un argument : # | With an argument: # | Con un argumento : # |
plurals_key:one | Voiture | Car | Coche |
plurals_key:other | Voitures | Cars | Coches |
https://guides.gradle.org/publishing-plugins-to-gradle-plugin-portal/
The following configuration should be set in your ~/.gradle/gradle.properties
file:
gradle.publish.key=<api_key>
gradle.publish.secret=<secret>
Then simply run following command:
$ ./gradlew publishPlugins
To make changes to this plugin and test them in your project, you can use Gradle's composite build feature:
-
Clone this repository
-
Add this to
settings.gradle
in your project:includeBuild('/path/to/gradle-android-i18n') { dependencySubstitution { substitute module("gradle.plugin.com.github.gradle:android-i18n") with project(':') } }
-
Now you can launch the
androidI18nImport
as usual from your project:cd /path/to/your/project ./gradlew app:androidI18nImport