✨ New gettext knockout binding
Allows to wrap a value into a gettext call to translate dynamic values (if a translation is available).
This commit is contained in:
1 parent
d8dc8131a2
commit
eb89369c6f
2 files changed
+17
No files matched your search
@@ -1759,6 +1759,7 @@ def collect_core_assets(preferred_stylesheet="css"):
|
||||
assets["js"] = [
|
||||
"js/app/bindings/allowbindings.js",
|
||||
"js/app/bindings/contextmenu.js",
|
||||
"js/app/bindings/gettext.js",
|
||||
"js/app/bindings/invisible.js",
|
||||
"js/app/bindings/popover.js",
|
||||
"js/app/bindings/qrcode.js",
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
ko.bindingHandlers.gettext = {
|
||||
init: function () {
|
||||
// Prevent binding on the dynamically-injected text node (as developers are unlikely to expect that, and it has security implications).
|
||||
// It should also make things faster, as we no longer have to consider whether the text node might be bindable.
|
||||
return {controlsDescendantBindings: true};
|
||||
},
|
||||
update: function (element, valueAccessor) {
|
||||
var gt =
|
||||
gettext ||
|
||||
function (text) {
|
||||
return text;
|
||||
};
|
||||
ko.utils.setTextContent(element, gt(valueAccessor()));
|
||||
}
|
||||
};
|
||||
ko.virtualElements.allowedBindings["gettext"] = true;
|
||||
Reference in new issue
Block a user