- Kotlin 95.8%
- Shell 4.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
Publish release to Forgejo / publish (push) Successful in 1m16s
|
||
| .forgejo/workflows | ||
| .run | ||
| gradle/wrapper | ||
| kotlin-js-store | ||
| kotlinx-gettext | ||
| kotlinx-gettext-gradle-plugin | ||
| kotlinx-gettext-plugin | ||
| sample | ||
| tools | ||
| .gitignore | ||
| build.gradle.kts | ||
| gradle.properties | ||
| gradlew | ||
| gradlew.bat | ||
| kotlinx-gettext.png | ||
| LICENSE | ||
| README.md | ||
| RELEASING.md | ||
| settings.gradle.kts | ||
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-gettextlibrary to use in your project to translate strings.kotlinx-gettext-pluginKotlin compiler plugin to extract strings for translation from Kotlin code.kotlinx-gettext-gradle-pluginto conveniently apply Kotlin compiler plugin in your Gradle build.
Usage
Library
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.
Translation
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"))
// Optional: scan only this main compilation instead of every target's main compilation.
compilationTasks.set(setOf("compileKotlinJs"))
}
Then invoke ./gradlew gettext to extract strings for translations into src/messages.pot.
Only main source compilations are used: test and JS/Wasm executable-link tasks are not scheduled
for extraction. With no explicit compilationTasks, the main compilation of every target is used.
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.
Fork releases
Instructions for publishing the Morwud plugin artifacts to Forgejo, including tag-based CI releases, are in RELEASING.md.
Known issues
- The library only supports Kotlin/JVM and Kotlin/JS as of now, Multiplatform Native port is in progress.
- .mo files are not (yet) supported.
