1 var Localize =
function(table){
3 this.locale =
"default";
9 Localize.prototype.setHeaderFilterPlaceholder =
function(placeholder){
10 this.langs.default.headerFilters.default = placeholder;
14 Localize.prototype.setHeaderFilterColumnPlaceholder =
function(column, placeholder){
15 this.langs.default.headerFilters.columns[column] = placeholder;
17 if(this.lang && !this.lang.headerFilters.columns[column]){
18 this.lang.headerFilters.columns[column] = placeholder;
23 Localize.prototype.installLang =
function(locale, lang){
24 if(this.langs[locale]){
25 this._setLangProp(this.langs[locale], lang);
27 this.langs[locale] = lang;
31 Localize.prototype._setLangProp =
function(lang, values){
32 for(let key in values){
33 if(lang[key] && typeof lang[key] ==
"object"){
34 this._setLangProp(lang[key], values[key])
36 lang[key] = values[key];
43 Localize.prototype.setLocale =
function(desiredLocale){
46 desiredLocale = desiredLocale ||
"default";
49 function traverseLang(trans, path){
50 for(var prop in trans){
52 if(typeof trans[prop] ==
"object"){
56 traverseLang(trans[prop], path[prop]);
58 path[prop] = trans[prop];
64 if(desiredLocale ===
true && navigator.language){
66 desiredLocale = navigator.language.toLowerCase();
72 if(!
self.langs[desiredLocale]){
73 let prefix = desiredLocale.split(
"-")[0];
75 if(
self.langs[prefix]){
76 console.warn(
"Localization Error - Exact matching locale not found, using closest match: ", desiredLocale, prefix);
77 desiredLocale = prefix;
79 console.warn(
"Localization Error - Matching locale not found, using default: ", desiredLocale);
80 desiredLocale =
"default";
85 self.locale = desiredLocale;
88 self.lang = Tabulator.prototype.helpers.deepClone(
self.langs.default || {});
90 if(desiredLocale !=
"default"){
91 traverseLang(
self.langs[desiredLocale],
self.lang);
94 self.table.options.localized.call(
self.table,
self.locale,
self.lang);
96 self._executeBindings();
100 Localize.prototype.getLocale =
function(locale){
105 Localize.prototype.getLang =
function(locale){
106 return locale ? this.langs[locale] : this.lang;
110 Localize.prototype.getText =
function(path, value){
111 var path = value ? path +
"|" + value : path,
112 pathArray = path.split(
"|"),
113 text = this._getLangElement(pathArray, this.locale);
123 Localize.prototype._getLangElement =
function(path, locale){
125 var root =
self.lang;
127 path.forEach(
function(level){
131 rootPath = root[level];
133 if(typeof rootPath !=
"undefined"){
145 Localize.prototype.bind =
function(path, callback){
146 if(!this.bindings[path]){
147 this.bindings[path] = [];
150 this.bindings[path].push(callback);
152 callback(this.getText(path), this.lang);
156 Localize.prototype._executeBindings =
function(){
159 for(let path in
self.bindings){
160 self.bindings[path].forEach(
function(binding){
161 binding(
self.getText(path),
self.lang);
167 Localize.prototype.langs = {
180 "page_size":
"Page Size",
182 "first_title":
"First Page",
184 "last_title":
"Last Page",
186 "prev_title":
"Prev Page",
188 "next_title":
"Next Page",
191 "default":
"filter column...",
197 Tabulator.prototype.registerModule(
"localize", Localize);