Resources generation in Kotlin Multiplatform
Find a file
Christian Basler 2339ae41e8
Some checks failed
Build / Assemble, test, and analyze (push) Failing after 18m21s
Try to fix jsBrowserTest
2026-06-20 17:15:00 +02:00
.forgejo/workflows Try to fix jsBrowserTest 2026-06-20 17:15:00 +02:00
buildSrc Switch to android-kmp-library 2026-06-20 07:17:19 +02:00
docs Version 2.0.0-alpha02 2025-08-17 12:23:27 +03:00
gradle Switch to android-kmp-library 2026-06-20 07:17:19 +02:00
gradle-plugin Switch to android-kmp-library 2026-06-20 07:17:19 +02:00
libres-compose Switch to android-kmp-library 2026-06-20 07:17:19 +02:00
libres-core Switch to android-kmp-library 2026-06-20 07:17:19 +02:00
libres-plural-rules Switch to android-kmp-library 2026-06-20 07:17:19 +02:00
plural-rules-generator Plural rules generator plugin 2025-08-17 11:32:39 +03:00
.gitignore Update libraries 2024-12-24 04:39:52 +03:00
build.gradle.kts Switch to android-kmp-library 2026-06-20 07:17:19 +02:00
gradle.properties Add string-array processing 2026-06-17 15:10:55 +02:00
gradlew Prepare for OpenSource 2023-02-02 23:22:06 +05:00
gradlew.bat Prepare for OpenSource 2023-02-02 23:22:06 +05:00
LICENSE Prepare for OpenSource 2023-02-02 23:22:06 +05:00
README.md Version 2.0.0-alpha02 2025-08-17 12:23:27 +03:00
settings.gradle.kts Update dependency versions 2026-06-19 16:41:04 +02:00

Libres

String resources generation in Kotlin Multiplatform.

Important

Starting from version 2.0.0, this plugin no longer supports image sharing.
If you want to continue using it for strings, youll need to migrate your image sharing to another solution — for example, Compose Multiplatform Resources.

Why?
I like my implementation for strings — having direct access to String is much more convenient than various wrappers in alternative solutions.
However, Im not happy with my implementation for images: it turned out to be unintuitive, dependent on the CocoaPods plugin on iOS, and rather unstable.
I dont have the time or motivation to maintain and improve this functionality, so I decided to remove it.

Setup

// build.gradle.kts (project)

buildscript {
    dependencies {
        classpath("io.github.skeptick.libres:gradle-plugin:2.0.0-alpha02")
    }
}
// build.gradle.kts (module)

plugins {
    id("io.github.skeptick.libres")
}

libres {
    generatedClassName = "MainRes" // "Res" by default
    generateNamedArguments = true // false by default
    baseLocaleLanguageCode = "ru" // "en" by default
    camelCaseNamesForAppleFramework = false // false by default
}

Supported platforms

  • Android, JVM, iOS, MacOS and JS in Kotlin Multiplatform projects.
  • Pure Android or JVM projects with Kotlin.

Known issues

Usage

Resources must be stored in {yourSourceSetName}/libres

Multiplatform:

├── commonMain
│   ├── kotlin
│   └── libres
│       └── strings
│           ├── strings_en.xml
│           └── strings_ru.xml

Android or JVM:

├── main
│   ├── java
│   └── libres
│       └── strings
│           ├── strings_en.xml
│           └── strings_ru.xml

Strings

Strings are stored in usual for Android form in xml files.
The file postfix must contain language code for which these strings are intended. E.g.: my_app_strings_en.xml
For each of languages you can create several files and they will be merged during compilation.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="simple_string">Hello!</string>
    <string name="string_with_arguments">Hello ${name}!</string>
    <plurals name="plural_string">
        <item quantity="one">resource</item>
        <item quantity="other">resources</item>
    </plurals>
</resources>

Kotlin:

MainRes.string.simple_string
MainRes.string.string_with_arguments.format(name = "John")
MainRes.string.plural_string.format(5)

Swift:

MainRes.shared.string.simple_string
// or MainRes.shared.string.simpleString if `camelCaseNamesForAppleFramework` enabled

Note

In this example MainRes.string.simple_string will return a string, so for better localization support it's not recommended to store the value. Get it directly at the place where it's displayed in UI. This seems familiar but ability to work directly with strings instead of resource IDs can be misused.


More about localization