From 9838b31b28c77cdbe878ca8db982f13fc883f43b Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Wed, 22 Aug 2018 13:38:19 +0200 Subject: I18n support in Handlebars templates. --- src/main/kotlin/pl/treksoft/kvision/html/Tag.kt | 12 ++++++++++-- src/main/kotlin/pl/treksoft/kvision/html/Template.kt | 10 ++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt index 03686fa0..48f6a9eb 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt @@ -124,6 +124,11 @@ open class Tag( * Text align. */ var align by refreshOnUpdate(align) + /** + * @suppress + * Internal property + */ + override var templateDataObj: Any? = null /** * Handlebars template. */ @@ -139,8 +144,11 @@ open class Tag( } override fun render(): VNode { - if (templateData != null && lastLanguage != null && lastLanguage != I18n.language) - templateData = templateData + if (templateDataObj != null && lastLanguage != null && lastLanguage != I18n.language) { + getRoot()?.renderDisabled = true + templateData = templateDataObj + getRoot()?.renderDisabled = false + } return if (content != null) { val translatedContent = content?.let { translate(it) } if (rich) { diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Template.kt b/src/main/kotlin/pl/treksoft/kvision/html/Template.kt index d430d8ff..9a52eb5b 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Template.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Template.kt @@ -29,18 +29,24 @@ import pl.treksoft.kvision.i18n.I18n interface Template { var content: String? var rich: Boolean + /** + * @suppress + * Internal property + */ + var templateDataObj: Any? var template: ((Any?) -> String)? - val templates: Map String> + var templates: Map String> /** * Handlebars template data object. */ var templateData: Any? get() { - return null + return templateDataObj } set(value) { if (!rich) rich = true + templateDataObj = value content = template?.invoke(value) ?: templates.get(I18n.language)?.invoke(value) } } -- cgit