Gettext compatible library and Gradle plugin
  • Kotlin 95.8%
  • Shell 4.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Morwud 52467f7001
All checks were successful
Publish release to Forgejo / publish (push) Successful in 1m16s
Add Forgejo tag release automation
2026-11-15 20:33:11 +01:00
.forgejo/workflows Add Forgejo tag release automation 2026-11-15 20:33:11 +01:00
.run minor test fixes 2022-06-20 15:44:33 +02:00
gradle/wrapper Fix compatibility with Kotlin 2.4.21 2026-10-16 23:12:15 +02:00
kotlin-js-store Fix compatibility with Kotlin 2.4.21 2026-10-16 23:12:15 +02:00
kotlinx-gettext Add Forgejo tag release automation 2026-11-15 20:33:11 +01:00
kotlinx-gettext-gradle-plugin Add Forgejo tag release automation 2026-11-15 20:33:11 +01:00
kotlinx-gettext-plugin Add Forgejo tag release automation 2026-11-15 20:33:11 +01:00
sample Limit gettext compilation scope 2026-11-15 17:07:12 +01:00
tools Add Forgejo tag release automation 2026-11-15 20:33:11 +01:00
.gitignore housekeeping 2025-02-27 17:53:52 +01:00
build.gradle.kts Limit gettext compilation scope 2026-11-15 17:07:12 +01:00
gradle.properties Update compiler plugin API usage and bump dependencies 2025-02-27 17:11:01 +01:00
gradlew upgrade Gradle to 8.4 2023-10-13 10:42:44 +02:00
gradlew.bat upgrade Gradle to 8.4 2023-10-13 10:42:44 +02:00
kotlinx-gettext.png update README 2022-09-26 14:45:01 +02:00
LICENSE set up basic project structure 2022-02-14 13:17:04 +01:00
README.md Add Forgejo tag release automation 2026-11-15 20:33:11 +01:00
RELEASING.md Add Forgejo tag release automation 2026-11-15 20:33:11 +01:00
settings.gradle.kts Add Forgejo tag release automation 2026-11-15 20:33:11 +01:00

Kotlinx Gettext

maven license

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:

  1. kotlinx-gettext library to use in your project to translate strings.
  2. kotlinx-gettext-plugin Kotlin compiler plugin to extract strings for translation from Kotlin code.
  3. kotlinx-gettext-gradle-plugin to 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.