An write-once-run-anywhere approach to localization in multiple platform project.
- Writes
ResourceBundle
for Java and XML values for Android. - Localization data can be placed within Gradle script or CSV file.
Using plugins DSL:
plugins {
id('com.hanggrian.localization') version "$version"
}
Using legacy plugin application:
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath("com.hanggrian:localization-gradle-plugin:$version")
}
}
apply plugin: 'com.hanggrian.localization'
Apply plugin in your module, and configure localization
extension like below:
localization {
resourceName.set('strings')
text('home') {
en = 'Home'
id = 'Beranda'
}
text('about') {
en = 'About'
id = 'Tentang'
}
}
tasks {
localizeJvm {
outputDirectory.set(new File('src/main/resources'))
}
localizeAndroid {
outputDirectory.set(new File('my/custom/directory'))
}
}
It's even simpler with Gradle Kotlin DSL.
localization {
"home" {
en = "Home"
id = "Beranda"
}
"about" {
en = "About"
id = "Tentang"
}
}
Then use command localizeJvm
or localizeAndroid
to write localization files
into their respective directory.