aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-08-22 13:38:19 +0200
committerRobert Jaros <rjaros@finn.pl>2018-08-22 14:14:21 +0200
commit9838b31b28c77cdbe878ca8db982f13fc883f43b (patch)
treebab520c002773a8ed393c9178483d82d1325ba90 /src/main
parent6bf1d12f6d64474af60c42bf1ee9bedc0d3dc8e5 (diff)
downloadkvision-9838b31b28c77cdbe878ca8db982f13fc883f43b.tar.gz
kvision-9838b31b28c77cdbe878ca8db982f13fc883f43b.tar.bz2
kvision-9838b31b28c77cdbe878ca8db982f13fc883f43b.zip
I18n support in Handlebars templates.0.0.17
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Tag.kt12
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Template.kt10
2 files changed, 18 insertions, 4 deletions
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
@@ -125,6 +125,11 @@ open class Tag(
*/
var align by refreshOnUpdate(align)
/**
+ * @suppress
+ * Internal property
+ */
+ override var templateDataObj: Any? = null
+ /**
* Handlebars template.
*/
override var template: ((Any?) -> String)? by refreshOnUpdate()
@@ -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, (Any?) -> String>
+ var templates: Map<String, (Any?) -> 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)
}
}