Store texts data in the element using them

This way we can have a generic function we can apply in other places.
This commit is contained in:
Javi Martín
2019-10-31 15:06:03 +01:00
parent e314701d49
commit 9e74ebccb6
3 changed files with 10 additions and 7 deletions

View File

@@ -75,11 +75,9 @@
App.Globalize.display_translations(locale);
},
update_description: function() {
var count, description;
var count;
count = App.Globalize.enabled_locales().length;
description = App.I18n.pluralize($(".globalize-languages").data("languages-description"), count);
$(".js-languages-description").text(description);
App.I18n.set_pluralize($(".js-languages-description"), count);
},
initialize: function() {
$(".js-add-language").on("change", function() {

View File

@@ -1,6 +1,9 @@
(function() {
"use strict";
App.I18n = {
set_pluralize: function(element, count) {
element.text(this.pluralize(element.data("texts"), count));
},
pluralize: function(texts, count) {
return this.raw_text(texts, count).replace("%{count}", count);
},