Carter
05/26/2021, 1:08 PMDirk Hoffmann
05/26/2021, 2:18 PMobject 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) }
}
}
Carter
05/26/2021, 7:11 PMDirk Hoffmann
05/26/2021, 9:53 PMI18N.get(keyOfString)
calls instead of "the String"
calls ...
What would you expect of an external Library to do more than that ??Carter
05/26/2021, 9:54 PM