Skip to content

Gettext library for Kotlin/Wasm and Kotlin/JS web applications

License

Notifications You must be signed in to change notification settings

rjaros/kilua-gettext

Repository files navigation

Kilua Gettext

This is a fork of the library implementing the main part of the kotlinx-gettext project. The library has been modified to work with Kotlin/JS and Kotlin/WasmJs targets in the browser environment. The original project is tightly coupled with Okio library, providing no real support for the browsers.

The main goal of this fork is to provide a simple and efficient way to use Gettext translations in Kotlin/JS and Kotlin/WasmJs web applications. Specifically, this library is used internally by the Kilua web framework.

Maven Central license

Usage

Library

Add the "dev.kilua:kilua-gettext:${version}" 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.

@JsModule("./de.po")
external object dePo : JsAny

val i18n = Gettext.load(Locale("de"), dePo.toString())
println(i18n.tr("Hello world!"))

Refer to GNU gettext documentation for more details.

Translation

You can use Gradle plugin from the original project to extract strings from Kotlin code and setup gettext task.