Are there any emerging conventions for localizatio...
# compose-desktop
c
Are there any emerging conventions for localization in Compose Desktop (and also hopefully Web)?
d
well, on my last search a few month's ago nothing "standard"y found ... as I stay on the desktop (non android/iOS) I use my own:
Copy code
object I18N  {
    private val translationBundles = HashMap<Locale, ResourceBundle>()
//    private var currentLocale = Locale("de", "DE")
    private var currentLocale = Locale("en", "GB")
    private var currentTranslations: ResourceBundle

    init {
        currentTranslations = try {
            currentTranslations = ResourceBundle.getBundle("i18n.translations", currentLocale)
            translationBundles[currentLocale] = currentTranslations
            currentTranslations
        }
        catch (except: MissingResourceException) {
            throw Exception("translation properties file not found: src/main/resources/i18n/translations_${currentLocale.toString()}.properties")
        }
    }

    operator fun get(key: String): String {
        return T(key)
    }
    fun T(key: String): String {
        return try {
            if (true == currentTranslations.containsKey(key)) currentTranslations.getString(key) else key
        }
        catch (except: ClassCastException) {
            "ClassCastException:${key}"
        }
    }
    fun T(keys: List<String>): List<String> {
        return keys.map { T(it) }
    }
}
c
I was afraid that might be the case.
d
well, that's what I thought also in the beginning ... but then ... localisation of Strings is not Rocket Science ... it is simply Resource Property files and static
I18N.get(keyOfString)
calls instead of
"the String"
calls ... What would you expect of an external Library to do more than that ??
c
Operate off of a standard format, for integration with localization services Deal with positional formatters Deal with plurals
And for the positional formatters, ideally support contextual information so translators know what the format string actually is.
Nice to have would be overlay or partial translation support for regions. Eg US versus UK