aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/html
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-08-22 13:24:03 +0200
committerRobert Jaros <rjaros@finn.pl>2018-08-22 13:24:03 +0200
commit0ad1af65697fd147270972599704eecda6e81a41 (patch)
tree75c24d1c6c7e89eea9b055108596864230bd2a3b /src/main/kotlin/pl/treksoft/kvision/html
parent1d86be75d10f3d5330776f6bab090d14dd1aa3a0 (diff)
downloadkvision-0ad1af65697fd147270972599704eecda6e81a41.tar.gz
kvision-0ad1af65697fd147270972599704eecda6e81a41.tar.bz2
kvision-0ad1af65697fd147270972599704eecda6e81a41.zip
I18n support in Handlebars templates.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/html')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Tag.kt6
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Template.kt13
2 files changed, 16 insertions, 3 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
index 3a15a4d0..ae26c5de 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
@@ -126,7 +126,11 @@ open class Tag(
/**
* Handlebars template.
*/
- override var template: (Any?) -> String by refreshOnUpdate()
+ override var template: ((Any?) -> String)? by refreshOnUpdate()
+ /**
+ * Handlebars templates for i18n.
+ */
+ override var templates: Map<String, (Any?) -> String>? by refreshOnUpdate()
init {
@Suppress("LeakingThis")
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Template.kt b/src/main/kotlin/pl/treksoft/kvision/html/Template.kt
index a042fc3c..31155209 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Template.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Template.kt
@@ -21,17 +21,26 @@
*/
package pl.treksoft.kvision.html
+import pl.treksoft.kvision.i18n.I18n
+
+/**
+ * Handlebars templates helper interface.
+ */
interface Template {
var content: String?
var rich: Boolean
- var template: (Any?) -> String
+ var template: ((Any?) -> String)?
+ val templates: Map<String, (Any?) -> String>?
+ /**
+ * Handlebars template data object.
+ */
var templateData: Any?
get() {
return null
}
set(value) {
if (!rich) rich = true
- content = template(value)
+ content = template?.invoke(value) ?: templates?.get(I18n.language)?.invoke(value)
}
}