
Implements Gettext for internationalization, featuring a library for string translation, a compiler plugin for extracting translatable strings, and a Gradle plugin for seamless integration, enhancing i18n workflows.
Gettext is a widely used internationalization (i18n) format supported by many tools. This project provides pure Kotlin implementation of Gettext.
The project consists of several parts:
kotlinx-gettext library to use in your project to translate strings.kotlinx-gettext-plugin Kotlin compiler plugin to extract strings for translation from Kotlin code.kotlinx-gettext-gradle-plugin to conveniently apply Kotlin compiler plugin in your Gradle build.Add the "name.kropp.kotlinx-gettext:kotlinx-gettext:0.7.0" to the dependencies of your project.
The library is available on Maven Central.
Load translated strings and apply translations using an instance of I18n class.
val i18n = Gettext.load(Locale.GERMAN, Thread.currentThread().contextClassLoader.getResourceAsStream("de.po")!!)
println(i18n.tr("Hello world!"))See sample module for a full example. Refer to GNU gettext documentation
for more details.
Apply Gradle plugin to extract strings and setup gettext task:
plugins {
id("name.kropp.kotlinx-gettext") version "0.7.0"
}
gettext {
potFile.set(File(projectDir, "src/messages.pot"))
keywords.set(listOf("tr","trn:1,2"))
}Then invoke ./gradlew gettext to extract strings for translations into src/messages.pot
Translate messages with any software or service supporting Gettext format. The result will be a number of .po files, which you should put into resources.
Gettext is a widely used internationalization (i18n) format supported by many tools. This project provides pure Kotlin implementation of Gettext.
The project consists of several parts:
kotlinx-gettext library to use in your project to translate strings.kotlinx-gettext-plugin Kotlin compiler plugin to extract strings for translation from Kotlin code.kotlinx-gettext-gradle-plugin to conveniently apply Kotlin compiler plugin in your Gradle build.Add the "name.kropp.kotlinx-gettext:kotlinx-gettext:0.7.0" to the dependencies of your project.
The library is available on Maven Central.
Load translated strings and apply translations using an instance of I18n class.
val i18n = Gettext.load(Locale.GERMAN, Thread.currentThread().contextClassLoader.getResourceAsStream("de.po")!!)
println(i18n.tr("Hello world!"))See sample module for a full example. Refer to GNU gettext documentation
for more details.
Apply Gradle plugin to extract strings and setup gettext task:
plugins {
id("name.kropp.kotlinx-gettext") version "0.7.0"
}
gettext {
potFile.set(File(projectDir, "src/messages.pot"))
keywords.set(listOf("tr","trn:1,2"))
}Then invoke ./gradlew gettext to extract strings for translations into src/messages.pot
Translate messages with any software or service supporting Gettext format. The result will be a number of .po files, which you should put into resources.