diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-08-22 02:29:28 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-08-22 02:29:28 +0200 |
commit | 1d86be75d10f3d5330776f6bab090d14dd1aa3a0 (patch) | |
tree | 0266a496486a78e50a1a0119f653680174176541 | |
parent | db000e6176e6e49a6a3f6b50ddbb8f0e5ae771a1 (diff) | |
download | kvision-1d86be75d10f3d5330776f6bab090d14dd1aa3a0.tar.gz kvision-1d86be75d10f3d5330776f6bab090d14dd1aa3a0.tar.bz2 kvision-1d86be75d10f3d5330776f6bab090d14dd1aa3a0.zip |
I18n fixes for modal components.
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/i18n/I18n.kt | 14 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt | 49 | ||||
-rw-r--r-- | webpack.config.d/jed.js | 3 | ||||
-rw-r--r-- | webpack.config.d/jquery.js | 3 | ||||
-rw-r--r-- | webpack.config.d/minify.js | 16 |
5 files changed, 58 insertions, 27 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/i18n/I18n.kt b/src/main/kotlin/pl/treksoft/kvision/i18n/I18n.kt index 9d2ee1db..ee7bad86 100644 --- a/src/main/kotlin/pl/treksoft/kvision/i18n/I18n.kt +++ b/src/main/kotlin/pl/treksoft/kvision/i18n/I18n.kt @@ -127,7 +127,12 @@ object I18n { return I18N_PLURAL_DELIMITER + singularKey + I18N_PLURAL_DELIMITER + pluralKey + I18N_PLURAL_DELIMITER + value } - internal fun trans(text: String): String { + /** + * A dynamic translation function. + * @param text text marked for a dynamic translation. + * @return translated text. + */ + fun trans(text: String): String { return if (text.startsWith(I18N_SINGLE_DELIMITER)) { gettext(text.substring(I18N_SINGLE_DELIMITER.length)) } else if (text.startsWith(I18N_PLURAL_DELIMITER)) { @@ -142,7 +147,12 @@ object I18n { } } - internal fun trans(text: String?): String? { + /** + * A dynamic translation function. + * @param text text marked for a dynamic translation. + * @return translated text. + */ + fun trans(text: String?): String? { return text?.let { trans(it) } diff --git a/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt b/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt index ffd67a1b..693ecbaa 100644 --- a/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt +++ b/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt @@ -22,8 +22,8 @@ package pl.treksoft.kvision.modal import pl.treksoft.kvision.html.Align -import pl.treksoft.kvision.html.ButtonStyle import pl.treksoft.kvision.html.Button +import pl.treksoft.kvision.html.ButtonStyle import pl.treksoft.kvision.html.TAG import pl.treksoft.kvision.html.Tag @@ -38,13 +38,16 @@ import pl.treksoft.kvision.html.Tag * @param size modal window size * @param animation determines if animations are used * @param cancelVisible determines if Cancel button is visible + * @param yesTitle yes button text + * @param noTitle no button text + * @param cancelTitle cancel button text * @param noCallback a function called after closing window with No button * @param yesCallback a function called after closing window with Yes button */ open class Confirm( caption: String? = null, text: String? = null, rich: Boolean = false, align: Align? = null, size: ModalSize? = null, animation: Boolean = true, - cancelVisible: Boolean = false, + cancelVisible: Boolean = false, yesTitle: String = "Yes", noTitle: String = "No", cancelTitle: String = "Cancel", private val noCallback: (() -> Unit)? = null, private val yesCallback: (() -> Unit)? = null ) : Modal(caption, false, size, animation, false) { @@ -77,8 +80,37 @@ open class Confirm( */ var cancelVisible by refreshOnUpdate(cancelVisible, { refreshCancelButton() }) + /** + * Yes button text. + */ + var yesTitle + get() = yesButton.text + set(value) { + yesButton.text = value + } + + /** + * No button text. + */ + var noTitle + get() = noButton.text + set(value) { + noButton.text = value + } + + /** + * Cancel button text. + */ + var cancelTitle + get() = cancelButton.text + set(value) { + cancelButton.text = value + } + private val contentTag = Tag(TAG.DIV, text, rich, align) - private val cancelButton = Button("Cancel", "remove") + private val cancelButton = Button(cancelTitle, "remove") + private val noButton = Button(noTitle, "ban-circle") + private val yesButton = Button(yesTitle, "ok", ButtonStyle.PRIMARY) init { body.add(contentTag) @@ -88,7 +120,6 @@ open class Confirm( } } this.addButton(cancelButton) - val noButton = Button("No", "ban-circle") noButton.setEventListener { click = { hide() @@ -96,7 +127,6 @@ open class Confirm( } } this.addButton(noButton) - val yesButton = Button("Yes", "ok", ButtonStyle.PRIMARY) yesButton.setEventListener { click = { hide() @@ -134,10 +164,13 @@ open class Confirm( fun show( caption: String? = null, text: String? = null, rich: Boolean = false, align: Align? = null, size: ModalSize? = null, animation: Boolean = true, - cancelVisible: Boolean = false, - noCallback: (() -> Unit)? = null, yesCallback: (() -> Unit)? = null + cancelVisible: Boolean = false, yesTitle: String = "Yes", noTitle: String = "No", + cancelTitle: String = "Cancel", noCallback: (() -> Unit)? = null, yesCallback: (() -> Unit)? = null ) { - Confirm(caption, text, rich, align, size, animation, cancelVisible, noCallback, yesCallback).show() + Confirm( + caption, text, rich, align, size, animation, cancelVisible, yesTitle, noTitle, cancelTitle, + noCallback, yesCallback + ).show() } } } diff --git a/webpack.config.d/jed.js b/webpack.config.d/jed.js new file mode 100644 index 00000000..a6d18464 --- /dev/null +++ b/webpack.config.d/jed.js @@ -0,0 +1,3 @@ +config.plugins.push(new webpack.ProvidePlugin({ + Jed: "jed" +})); diff --git a/webpack.config.d/jquery.js b/webpack.config.d/jquery.js index 40522595..bf5a1a20 100644 --- a/webpack.config.d/jquery.js +++ b/webpack.config.d/jquery.js @@ -1,4 +1,5 @@ config.plugins.push(new webpack.ProvidePlugin({ $: "jquery", - jQuery: "jquery" + jQuery: "jquery", + "window.jQuery": "jquery" })); diff --git a/webpack.config.d/minify.js b/webpack.config.d/minify.js deleted file mode 100644 index d85c861c..00000000 --- a/webpack.config.d/minify.js +++ /dev/null @@ -1,16 +0,0 @@ -if (defined.PRODUCTION) { - const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); - - config.optimization = { - minimizer: [ - new UglifyJSPlugin({ - uglifyOptions: { - compress: { - unused: false - } - } - }) - ] - } - -} |