mirego/trikot.kword

Dynamic i18N concept

Opened this issue · 2 comments

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>
}

I would opt for a method like setCurrentLanguage(language: Language) instead of exposing a BehaviorSubject in an interface, but this is a great idea! 💯

👍🏻

Absolutely, and thinking about it Language is not even a concept that exist in kword, that was specific to a use case I've had.

I've changed it to setCurrentVariantCodes(vararg codes: String) so if you would for instance only support languages as variants, then you would have to pass setCurrentVariantCodes("fr") but if you had other variants such as country setCurrentVariantCodes("fr", "CA")