Giter Club home page Giter Club logo

trikot.kword's Introduction

⚠️ Warning: this project as been moved

See the new trikot repository for releases starting from 3.0.0.

Trikot.KWord

Trikot.KWord provides the necessary tools to make localisation happen in Kotlin Multiplatform application.

  • A gradle plugin that generates Kotlin enum from Accent localisation files
  • Kotlin Multiplatform dependencies to interact with the localisation
  • Swift and Android extensions to change current locale to use.

Plugin usage

plugins {
    id 'mirego.kword' version '0.1'
}

kword {
    translationFile 'src/commonMain/resources/translations/translation.fr.json'
    enumClassName 'com.myproject.common.localization.KWordTranslation'
    generatedDir 'src/commonMain/generated'
}

kotlin {
    //...
    sourceSets {
        commonMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
            }
            kotlin.srcDir(kword.generatedDir)
        }
        //...
     }
}

tasks.findAll { it.name.startsWith('compile') }.each { it.dependsOn('kwordGenerateEnum') }

This will generate an enum Named KWordTranslation containing all the keys contained in your translationFile.

KWord usage

Common Code

for simple usage:

val myString = KWord[KWordTranslation.HELLO_WORLD]
For zero/singular/plural usage

To support language with multiple plurals, we adopt the interpolation pattern

Assuming the following translation key

{
  "plural": "{{count}} keys",
  "plural_0": "No keys",
  "plural_1": "One key",
  "plural_17": "Seventeen keys"
}

```kotlin
// "No keys"
KWord.t(KWordTranslation.PLURAL, 0)

// "One key"
KWord.t(KWordTranslation.PLURAL, 1)

// "2 keys"
KWord.t(KWordTranslation.PLURAL, 2)

// "3 keys"
KWord.t(KWordTranslation.PLURAL, 3)

// "Seventeen keys"
KWord.t(KWordTranslation.PLURAL, 17)

Installation

Import dependencies
    api "com.mirego.trikot:kword:$trikot_kword_version"
    jvm "com.mirego.trikot:kword-jvm:$trikot_kword_version"
    js "com.mirego.trikot:kword-js:$trikot_kword_version"
    iosx64 "com.mirego.trikot:kword-iosx64:$trikot_kword_version"
    iosarm64 "com.mirego.trikot:kword-iosarm64:$trikot_kword_version"

iOS

See swift extensions

Android

See android extensions

License

Trikot.kword is © 2018-2019 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md file.

About Mirego

Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We’re a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.

We also love open-source software and we try to give back to the community as much as we can.

trikot.kword's People

Contributors

antoinelamy avatar boubalou avatar frobert11 avatar gbourassa avatar hugolefrancois avatar jdtremblay avatar jfcartkeep avatar jpmartin avatar madumo avatar marcantoineg avatar martingagnon avatar mirego-builds avatar npresseault avatar wjobin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trikot.kword's Issues

Dynamic i18N concept

At this moment, KWord does not support changing language and string dynamically updating without re binding the strings.

We could add a concept similar to this and return Publishers instead of Strings so that when the language (or maybe variant) changes all is updated dynamically.

interface DynamicI18N {
    val i18N: Publisher<I18N>
    val currentI18N: I18N
    fun setCurrentVariantCodes(vararg codes: String)
    fun reset()
    operator fun get(key: KWordKey): Publisher<String>
    fun t(key: KWordKey): Publisher<String>
    fun t(key: KWordKey, vararg arguments: Pair<String, String>): Publisher<String>
    fun t(key: KWordKey, count: Int, vararg arguments: Pair<String, String>): Publisher<String>
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.