tabulator-tables 5.4.3 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc.json +3 -3
- package/.editorconfig +6 -6
- package/.eslintignore +3 -3
- package/.eslintrc.js +28 -28
- package/.github/ISSUE_TEMPLATE/bug_report.md +58 -58
- package/.github/ISSUE_TEMPLATE/documentation.md +14 -14
- package/.github/ISSUE_TEMPLATE/feature_request.md +24 -24
- package/.github/ISSUE_TEMPLATE/question.md +12 -12
- package/.github/workflows/bad-files-check.yml +39 -39
- package/.github/workflows/lint-and-test.yml +30 -30
- package/CODE_OF_CONDUCT.md +46 -46
- package/CONTRIBUTING.md +22 -22
- package/LICENSE +20 -20
- package/README.md +76 -76
- package/bower.json +40 -40
- package/build/Bundler.js +185 -185
- package/build/rollup.js +6 -6
- package/dist/css/tabulator.css +80 -53
- package/dist/css/tabulator.css.map +1 -1
- package/dist/css/tabulator.min.css +1 -1
- package/dist/css/tabulator.min.css.map +1 -1
- package/dist/css/tabulator_bootstrap3.css +89 -58
- package/dist/css/tabulator_bootstrap3.css.map +1 -1
- package/dist/css/tabulator_bootstrap3.min.css +1 -1
- package/dist/css/tabulator_bootstrap3.min.css.map +1 -1
- package/dist/css/tabulator_bootstrap4.css +106 -73
- package/dist/css/tabulator_bootstrap4.css.map +1 -1
- package/dist/css/tabulator_bootstrap4.min.css +1 -1
- package/dist/css/tabulator_bootstrap4.min.css.map +1 -1
- package/dist/css/tabulator_bootstrap5.css +110 -75
- package/dist/css/tabulator_bootstrap5.css.map +1 -1
- package/dist/css/tabulator_bootstrap5.min.css +1 -1
- package/dist/css/tabulator_bootstrap5.min.css.map +1 -1
- package/dist/css/tabulator_bulma.css +95 -62
- package/dist/css/tabulator_bulma.css.map +1 -1
- package/dist/css/tabulator_bulma.min.css +1 -1
- package/dist/css/tabulator_bulma.min.css.map +1 -1
- package/dist/css/tabulator_materialize.css +93 -63
- package/dist/css/tabulator_materialize.css.map +1 -1
- package/dist/css/tabulator_materialize.min.css +1 -1
- package/dist/css/tabulator_materialize.min.css.map +1 -1
- package/dist/css/tabulator_midnight.css +90 -59
- package/dist/css/tabulator_midnight.css.map +1 -1
- package/dist/css/tabulator_midnight.min.css +1 -1
- package/dist/css/tabulator_midnight.min.css.map +1 -1
- package/dist/css/tabulator_modern.css +96 -62
- package/dist/css/tabulator_modern.css.map +1 -1
- package/dist/css/tabulator_modern.min.css +1 -1
- package/dist/css/tabulator_modern.min.css.map +1 -1
- package/dist/css/tabulator_semanticui.css +233 -182
- package/dist/css/tabulator_semanticui.css.map +1 -1
- package/dist/css/tabulator_semanticui.min.css +1 -1
- package/dist/css/tabulator_semanticui.min.css.map +1 -1
- package/dist/css/tabulator_simple.css +80 -53
- package/dist/css/tabulator_simple.css.map +1 -1
- package/dist/css/tabulator_simple.min.css +1 -1
- package/dist/css/tabulator_simple.min.css.map +1 -1
- package/dist/css/tabulator_site.css +88 -57
- package/dist/css/tabulator_site.css.map +1 -1
- package/dist/css/tabulator_site.min.css +1 -1
- package/dist/css/tabulator_site.min.css.map +1 -1
- package/dist/js/jquery_wrapper.js +55 -55
- package/dist/js/tabulator.js +26054 -25713
- package/dist/js/tabulator.js.map +1 -1
- package/dist/js/tabulator.min.js +2 -2
- package/dist/js/tabulator.min.js.map +1 -1
- package/dist/js/tabulator_esm.js +26131 -25790
- package/dist/js/tabulator_esm.js.map +1 -1
- package/dist/js/tabulator_esm.min.js +2 -2
- package/dist/js/tabulator_esm.min.js.map +1 -1
- package/package.json +65 -65
- package/src/js/builds/esm.js +14 -14
- package/src/js/builds/jquery_wrapper.js +55 -55
- package/src/js/core/ColumnManager.js +745 -730
- package/src/js/core/CoreFeature.js +138 -138
- package/src/js/core/FooterManager.js +101 -101
- package/src/js/core/Module.js +141 -141
- package/src/js/core/RowManager.js +1128 -1101
- package/src/js/core/Tabulator.js +895 -892
- package/src/js/core/TabulatorFull.js +10 -10
- package/src/js/core/cell/Cell.js +295 -295
- package/src/js/core/cell/CellComponent.js +78 -76
- package/src/js/core/column/Column.js +949 -949
- package/src/js/core/column/ColumnComponent.js +152 -152
- package/src/js/core/column/defaults/options.js +17 -17
- package/src/js/core/defaults/options.js +65 -65
- package/src/js/core/modules/core.js +2 -2
- package/src/js/core/modules/optional.js +34 -34
- package/src/js/core/rendering/Renderer.js +203 -203
- package/src/js/core/rendering/renderers/BasicHorizontal.js +24 -19
- package/src/js/core/rendering/renderers/BasicVertical.js +83 -79
- package/src/js/core/rendering/renderers/VirtualDomHorizontal.js +582 -577
- package/src/js/core/rendering/renderers/VirtualDomVertical.js +634 -580
- package/src/js/core/row/PseudoRow.js +44 -44
- package/src/js/core/row/Row.js +457 -457
- package/src/js/core/row/RowComponent.js +93 -93
- package/src/js/core/tools/Alert.js +61 -61
- package/src/js/core/tools/ComponentFunctionBinder.js +32 -32
- package/src/js/core/tools/DataLoader.js +119 -119
- package/src/js/core/tools/DeprecationAdvisor.js +46 -46
- package/src/js/core/tools/ExternalEventBus.js +104 -104
- package/src/js/core/tools/Helpers.js +46 -46
- package/src/js/core/tools/InteractionMonitor.js +321 -321
- package/src/js/core/tools/InternalEventBus.js +161 -161
- package/src/js/core/tools/ModuleBinder.js +104 -104
- package/src/js/core/tools/OptionsList.js +44 -40
- package/src/js/core/tools/Popup.js +304 -304
- package/src/js/core/tools/TableRegistry.js +61 -61
- package/src/js/modules/Accessor/Accessor.js +115 -115
- package/src/js/modules/Ajax/Ajax.js +143 -143
- package/src/js/modules/Ajax/defaults/config.js +2 -2
- package/src/js/modules/Ajax/defaults/contentTypeFormatters.js +44 -44
- package/src/js/modules/Ajax/defaults/loaderPromise.js +86 -86
- package/src/js/modules/Ajax/defaults/urlGenerator.js +43 -43
- package/src/js/modules/Clipboard/Clipboard.js +279 -279
- package/src/js/modules/Clipboard/defaults/pasteActions.js +10 -10
- package/src/js/modules/Clipboard/defaults/pasteParsers.js +74 -74
- package/src/js/modules/ColumnCalcs/CalcComponent.js +47 -47
- package/src/js/modules/ColumnCalcs/ColumnCalcs.js +581 -568
- package/src/js/modules/ColumnCalcs/defaults/calculations.js +92 -85
- package/src/js/modules/Comms/Comms.js +51 -51
- package/src/js/modules/DataTree/DataTree.js +603 -603
- package/src/js/modules/Download/Download.js +148 -148
- package/src/js/modules/Download/defaults/downloaders/csv.js +61 -61
- package/src/js/modules/Download/defaults/downloaders/html.js +4 -4
- package/src/js/modules/Download/defaults/downloaders/json.js +33 -33
- package/src/js/modules/Download/defaults/downloaders/jsonLines.js +31 -31
- package/src/js/modules/Download/defaults/downloaders/pdf.js +111 -111
- package/src/js/modules/Download/defaults/downloaders/xlsx.js +102 -99
- package/src/js/modules/Download/defaults/downloaders.js +14 -14
- package/src/js/modules/Edit/Edit.js +734 -736
- package/src/js/modules/Edit/List.js +1048 -1033
- package/src/js/modules/Edit/defaults/editors/autocomplete.js +11 -11
- package/src/js/modules/Edit/defaults/editors/date.js +138 -110
- package/src/js/modules/Edit/defaults/editors/datetime.js +125 -97
- package/src/js/modules/Edit/defaults/editors/input.js +76 -74
- package/src/js/modules/Edit/defaults/editors/list.js +6 -6
- package/src/js/modules/Edit/defaults/editors/number.js +109 -107
- package/src/js/modules/Edit/defaults/editors/progress.js +126 -126
- package/src/js/modules/Edit/defaults/editors/range.js +80 -78
- package/src/js/modules/Edit/defaults/editors/select.js +9 -9
- package/src/js/modules/Edit/defaults/editors/star.js +145 -145
- package/src/js/modules/Edit/defaults/editors/textarea.js +122 -120
- package/src/js/modules/Edit/defaults/editors/tickCross.js +94 -96
- package/src/js/modules/Edit/defaults/editors/time.js +126 -98
- package/src/js/modules/Edit/defaults/editors.js +28 -28
- package/src/js/modules/Edit/inputMask.js +73 -73
- package/src/js/modules/Export/Export.js +626 -623
- package/src/js/modules/Export/ExportColumn.js +10 -10
- package/src/js/modules/Export/ExportRow.js +9 -9
- package/src/js/modules/Filter/Filter.js +903 -892
- package/src/js/modules/Filter/defaults/filters.js +107 -107
- package/src/js/modules/Format/Format.js +215 -212
- package/src/js/modules/Format/defaults/formatters/buttonCross.js +2 -2
- package/src/js/modules/Format/defaults/formatters/buttonTick.js +2 -2
- package/src/js/modules/Format/defaults/formatters/color.js +3 -3
- package/src/js/modules/Format/defaults/formatters/datetime.js +36 -36
- package/src/js/modules/Format/defaults/formatters/datetimediff.js +40 -40
- package/src/js/modules/Format/defaults/formatters/handle.js +3 -3
- package/src/js/modules/Format/defaults/formatters/html.js +2 -2
- package/src/js/modules/Format/defaults/formatters/image.js +39 -39
- package/src/js/modules/Format/defaults/formatters/link.js +77 -77
- package/src/js/modules/Format/defaults/formatters/lookup.js +9 -9
- package/src/js/modules/Format/defaults/formatters/money.js +43 -36
- package/src/js/modules/Format/defaults/formatters/plaintext.js +2 -2
- package/src/js/modules/Format/defaults/formatters/progress.js +132 -132
- package/src/js/modules/Format/defaults/formatters/responsiveCollapse.js +43 -43
- package/src/js/modules/Format/defaults/formatters/rowSelection.js +59 -59
- package/src/js/modules/Format/defaults/formatters/rownum.js +9 -9
- package/src/js/modules/Format/defaults/formatters/star.js +37 -37
- package/src/js/modules/Format/defaults/formatters/textarea.js +3 -3
- package/src/js/modules/Format/defaults/formatters/tickCross.js +21 -21
- package/src/js/modules/Format/defaults/formatters/traffic.js +46 -46
- package/src/js/modules/Format/defaults/formatters.js +42 -42
- package/src/js/modules/FrozenColumns/FrozenColumns.js +299 -299
- package/src/js/modules/FrozenRows/FrozenRows.js +169 -159
- package/src/js/modules/GroupRows/Group.js +597 -598
- package/src/js/modules/GroupRows/GroupComponent.js +70 -66
- package/src/js/modules/GroupRows/GroupRows.js +639 -639
- package/src/js/modules/History/History.js +171 -171
- package/src/js/modules/History/defaults/redoers.js +24 -24
- package/src/js/modules/History/defaults/undoers.js +24 -24
- package/src/js/modules/HtmlTableImport/HtmlTableImport.js +181 -181
- package/src/js/modules/Import/Import.js +193 -193
- package/src/js/modules/Import/defaults/importers/array.js +4 -4
- package/src/js/modules/Import/defaults/importers/csv.js +62 -62
- package/src/js/modules/Import/defaults/importers/json.js +7 -7
- package/src/js/modules/Import/defaults/importers.js +8 -8
- package/src/js/modules/Interaction/Interaction.js +337 -325
- package/src/js/modules/Keybindings/Keybindings.js +172 -172
- package/src/js/modules/Keybindings/defaults/actions.js +118 -118
- package/src/js/modules/Keybindings/defaults/bindings.js +12 -12
- package/src/js/modules/Layout/Layout.js +49 -49
- package/src/js/modules/Layout/defaults/modes/fitColumns.js +171 -171
- package/src/js/modules/Layout/defaults/modes/fitData.js +9 -9
- package/src/js/modules/Layout/defaults/modes/fitDataGeneral.js +9 -9
- package/src/js/modules/Layout/defaults/modes/fitDataStretch.js +39 -39
- package/src/js/modules/Layout/defaults/modes.js +11 -11
- package/src/js/modules/Localize/Localize.js +185 -185
- package/src/js/modules/Localize/defaults/langs.js +36 -36
- package/src/js/modules/Menu/Menu.js +302 -302
- package/src/js/modules/MoveColumns/MoveColumns.js +299 -299
- package/src/js/modules/MoveRows/MoveRows.js +635 -635
- package/src/js/modules/Mutator/Mutator.js +161 -161
- package/src/js/modules/Page/Page.js +881 -881
- package/src/js/modules/Page/defaults/pageCounters/pages.js +32 -32
- package/src/js/modules/Page/defaults/pageCounters/rows.js +39 -39
- package/src/js/modules/Page/defaults/pageCounters.js +7 -7
- package/src/js/modules/Persistence/Persistence.js +472 -458
- package/src/js/modules/Persistence/defaults/readers.js +29 -29
- package/src/js/modules/Persistence/defaults/writers.js +12 -12
- package/src/js/modules/Popup/Popup.js +231 -231
- package/src/js/modules/Print/Print.js +137 -137
- package/src/js/modules/ReactiveData/ReactiveData.js +408 -408
- package/src/js/modules/ResizeColumns/ResizeColumns.js +309 -309
- package/src/js/modules/ResizeRows/ResizeRows.js +111 -111
- package/src/js/modules/ResizeTable/ResizeTable.js +159 -159
- package/src/js/modules/ResponsiveLayout/ResponsiveLayout.js +348 -345
- package/src/js/modules/SelectRow/SelectRow.js +474 -444
- package/src/js/modules/Sort/Sort.js +470 -470
- package/src/js/modules/Sort/defaults/sorters/alphanum.js +43 -43
- package/src/js/modules/Sort/defaults/sorters/array.js +53 -53
- package/src/js/modules/Sort/defaults/sorters/boolean.js +6 -6
- package/src/js/modules/Sort/defaults/sorters/date.js +9 -9
- package/src/js/modules/Sort/defaults/sorters/datetime.js +43 -43
- package/src/js/modules/Sort/defaults/sorters/exists.js +6 -6
- package/src/js/modules/Sort/defaults/sorters/number.js +39 -39
- package/src/js/modules/Sort/defaults/sorters/string.js +33 -33
- package/src/js/modules/Sort/defaults/sorters/time.js +9 -9
- package/src/js/modules/Sort/defaults/sorters.js +20 -20
- package/src/js/modules/Tooltip/Tooltip.js +130 -130
- package/src/js/modules/Validate/Validate.js +305 -305
- package/src/js/modules/Validate/defaults/validators.js +138 -138
- package/src/scss/tabulator.scss +1496 -1467
- package/src/scss/themes/bootstrap/functions4.scss +118 -118
- package/src/scss/themes/bootstrap/functions5.scss +302 -302
- package/src/scss/themes/bootstrap/tabulator_bootstrap3.scss +288 -284
- package/src/scss/themes/bootstrap/tabulator_bootstrap4.scss +552 -544
- package/src/scss/themes/bootstrap/tabulator_bootstrap5.scss +584 -574
- package/src/scss/themes/bootstrap/variables3.scss +870 -870
- package/src/scss/themes/bootstrap/variables4.scss +930 -930
- package/src/scss/themes/bootstrap/variables5.scss +1641 -1641
- package/src/scss/themes/bulma/tabulator_bulma.scss +258 -252
- package/src/scss/themes/bulma/variables.scss +197 -197
- package/src/scss/themes/materialize/tabulator_materialize.scss +269 -265
- package/src/scss/themes/materialize/variables.scss +70 -70
- package/src/scss/themes/semanticui/tabulator_semanticui.scss +586 -561
- package/src/scss/themes/semanticui/variables.scss +839 -839
- package/src/scss/themes/semanticui/variables_table.scss +247 -247
- package/src/scss/themes/tabulator_midnight.scss +162 -158
- package/src/scss/themes/tabulator_modern.scss +239 -231
- package/src/scss/themes/tabulator_simple.scss +102 -102
- package/src/scss/themes/tabulator_site.scss +193 -189
|
@@ -1,186 +1,186 @@
|
|
|
1
|
-
import Module from '../../core/Module.js';
|
|
2
|
-
|
|
3
|
-
import Helpers from '../../core/tools/Helpers.js';
|
|
4
|
-
|
|
5
|
-
import defaultLangs from './defaults/langs.js';
|
|
6
|
-
|
|
7
|
-
class Localize extends Module{
|
|
8
|
-
|
|
9
|
-
constructor(table){
|
|
10
|
-
super(table);
|
|
11
|
-
|
|
12
|
-
this.locale = "default"; //current locale
|
|
13
|
-
this.lang = false; //current language
|
|
14
|
-
this.bindings = {}; //update events to call when locale is changed
|
|
15
|
-
this.langList = {};
|
|
16
|
-
|
|
17
|
-
this.registerTableOption("locale", false); //current system language
|
|
18
|
-
this.registerTableOption("langs", {});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
initialize(){
|
|
22
|
-
this.langList = Helpers.deepClone(Localize.langs);
|
|
23
|
-
|
|
24
|
-
if(this.table.options.columnDefaults.headerFilterPlaceholder !== false){
|
|
25
|
-
this.setHeaderFilterPlaceholder(this.table.options.columnDefaults.headerFilterPlaceholder);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
for(let locale in this.table.options.langs){
|
|
29
|
-
this.installLang(locale, this.table.options.langs[locale]);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this.setLocale(this.table.options.locale);
|
|
33
|
-
|
|
34
|
-
this.registerTableFunction("setLocale", this.setLocale.bind(this));
|
|
35
|
-
this.registerTableFunction("getLocale", this.getLocale.bind(this));
|
|
36
|
-
this.registerTableFunction("getLang", this.getLang.bind(this));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
//set header placeholder
|
|
40
|
-
setHeaderFilterPlaceholder(placeholder){
|
|
41
|
-
this.langList.default.headerFilters.default = placeholder;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
//setup a lang description object
|
|
45
|
-
installLang(locale, lang){
|
|
46
|
-
if(this.langList[locale]){
|
|
47
|
-
this._setLangProp(this.langList[locale], lang);
|
|
48
|
-
}else{
|
|
49
|
-
this.langList[locale] = lang;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
_setLangProp(lang, values){
|
|
54
|
-
for(let key in values){
|
|
55
|
-
if(lang[key] && typeof lang[key] == "object"){
|
|
56
|
-
this._setLangProp(lang[key], values[key]);
|
|
57
|
-
}else{
|
|
58
|
-
lang[key] = values[key];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
//set current locale
|
|
64
|
-
setLocale(desiredLocale){
|
|
65
|
-
desiredLocale = desiredLocale || "default";
|
|
66
|
-
|
|
67
|
-
//fill in any matching language values
|
|
68
|
-
function traverseLang(trans, path){
|
|
69
|
-
for(var prop in trans){
|
|
70
|
-
if(typeof trans[prop] == "object"){
|
|
71
|
-
if(!path[prop]){
|
|
72
|
-
path[prop] = {};
|
|
73
|
-
}
|
|
74
|
-
traverseLang(trans[prop], path[prop]);
|
|
75
|
-
}else{
|
|
76
|
-
path[prop] = trans[prop];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
//determining correct locale to load
|
|
82
|
-
if(desiredLocale === true && navigator.language){
|
|
83
|
-
//get local from system
|
|
84
|
-
desiredLocale = navigator.language.toLowerCase();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if(desiredLocale){
|
|
88
|
-
//if locale is not set, check for matching top level locale else use default
|
|
89
|
-
if(!this.langList[desiredLocale]){
|
|
90
|
-
let prefix = desiredLocale.split("-")[0];
|
|
91
|
-
|
|
92
|
-
if(this.langList[prefix]){
|
|
93
|
-
console.warn("Localization Error - Exact matching locale not found, using closest match: ", desiredLocale, prefix);
|
|
94
|
-
desiredLocale = prefix;
|
|
95
|
-
}else{
|
|
96
|
-
console.warn("Localization Error - Matching locale not found, using default: ", desiredLocale);
|
|
97
|
-
desiredLocale = "default";
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
this.locale = desiredLocale;
|
|
103
|
-
|
|
104
|
-
//load default lang template
|
|
105
|
-
this.lang = Helpers.deepClone(this.langList.default || {});
|
|
106
|
-
|
|
107
|
-
if(desiredLocale != "default"){
|
|
108
|
-
traverseLang(this.langList[desiredLocale], this.lang);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
this.dispatchExternal("localized", this.locale, this.lang);
|
|
112
|
-
|
|
113
|
-
this._executeBindings();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
//get current locale
|
|
117
|
-
getLocale(locale){
|
|
118
|
-
return this.locale;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
//get lang object for given local or current if none provided
|
|
122
|
-
getLang(locale){
|
|
123
|
-
return locale ? this.langList[locale] : this.lang;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
//get text for current locale
|
|
127
|
-
getText(path, value){
|
|
128
|
-
var fillPath = value ? path + "|" + value : path,
|
|
129
|
-
pathArray = fillPath.split("|"),
|
|
130
|
-
text = this._getLangElement(pathArray, this.locale);
|
|
131
|
-
|
|
132
|
-
// if(text === false){
|
|
133
|
-
// console.warn("Localization Error - Matching localized text not found for given path: ", path);
|
|
134
|
-
// }
|
|
135
|
-
|
|
136
|
-
return text || "";
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
//traverse langs object and find localized copy
|
|
140
|
-
_getLangElement(path, locale){
|
|
141
|
-
var root = this.lang;
|
|
142
|
-
|
|
143
|
-
path.forEach(function(level){
|
|
144
|
-
var rootPath;
|
|
145
|
-
|
|
146
|
-
if(root){
|
|
147
|
-
rootPath = root[level];
|
|
148
|
-
|
|
149
|
-
if(typeof rootPath != "undefined"){
|
|
150
|
-
root = rootPath;
|
|
151
|
-
}else{
|
|
152
|
-
root = false;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
return root;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
//set update binding
|
|
161
|
-
bind(path, callback){
|
|
162
|
-
if(!this.bindings[path]){
|
|
163
|
-
this.bindings[path] = [];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
this.bindings[path].push(callback);
|
|
167
|
-
|
|
168
|
-
callback(this.getText(path), this.lang);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
//iterate through bindings and trigger updates
|
|
172
|
-
_executeBindings(){
|
|
173
|
-
for(let path in this.bindings){
|
|
174
|
-
this.bindings[path].forEach((binding) => {
|
|
175
|
-
binding(this.getText(path), this.lang);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
Localize.moduleName = "localize";
|
|
182
|
-
|
|
183
|
-
//load defaults
|
|
184
|
-
Localize.langs = defaultLangs;
|
|
185
|
-
|
|
1
|
+
import Module from '../../core/Module.js';
|
|
2
|
+
|
|
3
|
+
import Helpers from '../../core/tools/Helpers.js';
|
|
4
|
+
|
|
5
|
+
import defaultLangs from './defaults/langs.js';
|
|
6
|
+
|
|
7
|
+
class Localize extends Module{
|
|
8
|
+
|
|
9
|
+
constructor(table){
|
|
10
|
+
super(table);
|
|
11
|
+
|
|
12
|
+
this.locale = "default"; //current locale
|
|
13
|
+
this.lang = false; //current language
|
|
14
|
+
this.bindings = {}; //update events to call when locale is changed
|
|
15
|
+
this.langList = {};
|
|
16
|
+
|
|
17
|
+
this.registerTableOption("locale", false); //current system language
|
|
18
|
+
this.registerTableOption("langs", {});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
initialize(){
|
|
22
|
+
this.langList = Helpers.deepClone(Localize.langs);
|
|
23
|
+
|
|
24
|
+
if(this.table.options.columnDefaults.headerFilterPlaceholder !== false){
|
|
25
|
+
this.setHeaderFilterPlaceholder(this.table.options.columnDefaults.headerFilterPlaceholder);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for(let locale in this.table.options.langs){
|
|
29
|
+
this.installLang(locale, this.table.options.langs[locale]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.setLocale(this.table.options.locale);
|
|
33
|
+
|
|
34
|
+
this.registerTableFunction("setLocale", this.setLocale.bind(this));
|
|
35
|
+
this.registerTableFunction("getLocale", this.getLocale.bind(this));
|
|
36
|
+
this.registerTableFunction("getLang", this.getLang.bind(this));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//set header placeholder
|
|
40
|
+
setHeaderFilterPlaceholder(placeholder){
|
|
41
|
+
this.langList.default.headerFilters.default = placeholder;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//setup a lang description object
|
|
45
|
+
installLang(locale, lang){
|
|
46
|
+
if(this.langList[locale]){
|
|
47
|
+
this._setLangProp(this.langList[locale], lang);
|
|
48
|
+
}else{
|
|
49
|
+
this.langList[locale] = lang;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_setLangProp(lang, values){
|
|
54
|
+
for(let key in values){
|
|
55
|
+
if(lang[key] && typeof lang[key] == "object"){
|
|
56
|
+
this._setLangProp(lang[key], values[key]);
|
|
57
|
+
}else{
|
|
58
|
+
lang[key] = values[key];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//set current locale
|
|
64
|
+
setLocale(desiredLocale){
|
|
65
|
+
desiredLocale = desiredLocale || "default";
|
|
66
|
+
|
|
67
|
+
//fill in any matching language values
|
|
68
|
+
function traverseLang(trans, path){
|
|
69
|
+
for(var prop in trans){
|
|
70
|
+
if(typeof trans[prop] == "object"){
|
|
71
|
+
if(!path[prop]){
|
|
72
|
+
path[prop] = {};
|
|
73
|
+
}
|
|
74
|
+
traverseLang(trans[prop], path[prop]);
|
|
75
|
+
}else{
|
|
76
|
+
path[prop] = trans[prop];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//determining correct locale to load
|
|
82
|
+
if(desiredLocale === true && navigator.language){
|
|
83
|
+
//get local from system
|
|
84
|
+
desiredLocale = navigator.language.toLowerCase();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if(desiredLocale){
|
|
88
|
+
//if locale is not set, check for matching top level locale else use default
|
|
89
|
+
if(!this.langList[desiredLocale]){
|
|
90
|
+
let prefix = desiredLocale.split("-")[0];
|
|
91
|
+
|
|
92
|
+
if(this.langList[prefix]){
|
|
93
|
+
console.warn("Localization Error - Exact matching locale not found, using closest match: ", desiredLocale, prefix);
|
|
94
|
+
desiredLocale = prefix;
|
|
95
|
+
}else{
|
|
96
|
+
console.warn("Localization Error - Matching locale not found, using default: ", desiredLocale);
|
|
97
|
+
desiredLocale = "default";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.locale = desiredLocale;
|
|
103
|
+
|
|
104
|
+
//load default lang template
|
|
105
|
+
this.lang = Helpers.deepClone(this.langList.default || {});
|
|
106
|
+
|
|
107
|
+
if(desiredLocale != "default"){
|
|
108
|
+
traverseLang(this.langList[desiredLocale], this.lang);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this.dispatchExternal("localized", this.locale, this.lang);
|
|
112
|
+
|
|
113
|
+
this._executeBindings();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//get current locale
|
|
117
|
+
getLocale(locale){
|
|
118
|
+
return this.locale;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//get lang object for given local or current if none provided
|
|
122
|
+
getLang(locale){
|
|
123
|
+
return locale ? this.langList[locale] : this.lang;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//get text for current locale
|
|
127
|
+
getText(path, value){
|
|
128
|
+
var fillPath = value ? path + "|" + value : path,
|
|
129
|
+
pathArray = fillPath.split("|"),
|
|
130
|
+
text = this._getLangElement(pathArray, this.locale);
|
|
131
|
+
|
|
132
|
+
// if(text === false){
|
|
133
|
+
// console.warn("Localization Error - Matching localized text not found for given path: ", path);
|
|
134
|
+
// }
|
|
135
|
+
|
|
136
|
+
return text || "";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//traverse langs object and find localized copy
|
|
140
|
+
_getLangElement(path, locale){
|
|
141
|
+
var root = this.lang;
|
|
142
|
+
|
|
143
|
+
path.forEach(function(level){
|
|
144
|
+
var rootPath;
|
|
145
|
+
|
|
146
|
+
if(root){
|
|
147
|
+
rootPath = root[level];
|
|
148
|
+
|
|
149
|
+
if(typeof rootPath != "undefined"){
|
|
150
|
+
root = rootPath;
|
|
151
|
+
}else{
|
|
152
|
+
root = false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return root;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
//set update binding
|
|
161
|
+
bind(path, callback){
|
|
162
|
+
if(!this.bindings[path]){
|
|
163
|
+
this.bindings[path] = [];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
this.bindings[path].push(callback);
|
|
167
|
+
|
|
168
|
+
callback(this.getText(path), this.lang);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//iterate through bindings and trigger updates
|
|
172
|
+
_executeBindings(){
|
|
173
|
+
for(let path in this.bindings){
|
|
174
|
+
this.bindings[path].forEach((binding) => {
|
|
175
|
+
binding(this.getText(path), this.lang);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
Localize.moduleName = "localize";
|
|
182
|
+
|
|
183
|
+
//load defaults
|
|
184
|
+
Localize.langs = defaultLangs;
|
|
185
|
+
|
|
186
186
|
export default Localize;
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
"default":{ //hold default locale text
|
|
3
|
-
"groups":{
|
|
4
|
-
"item":"item",
|
|
5
|
-
"items":"items",
|
|
6
|
-
},
|
|
7
|
-
"columns":{
|
|
8
|
-
},
|
|
9
|
-
"data":{
|
|
10
|
-
"loading":"Loading",
|
|
11
|
-
"error":"Error",
|
|
12
|
-
},
|
|
13
|
-
"pagination":{
|
|
14
|
-
"page_size":"Page Size",
|
|
15
|
-
"page_title":"Show Page",
|
|
16
|
-
"first":"First",
|
|
17
|
-
"first_title":"First Page",
|
|
18
|
-
"last":"Last",
|
|
19
|
-
"last_title":"Last Page",
|
|
20
|
-
"prev":"Prev",
|
|
21
|
-
"prev_title":"Prev Page",
|
|
22
|
-
"next":"Next",
|
|
23
|
-
"next_title":"Next Page",
|
|
24
|
-
"all":"All",
|
|
25
|
-
"counter":{
|
|
26
|
-
"showing": "Showing",
|
|
27
|
-
"of": "of",
|
|
28
|
-
"rows": "rows",
|
|
29
|
-
"pages": "pages",
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"headerFilters":{
|
|
33
|
-
"default":"filter column...",
|
|
34
|
-
"columns":{}
|
|
35
|
-
}
|
|
36
|
-
},
|
|
1
|
+
export default {
|
|
2
|
+
"default":{ //hold default locale text
|
|
3
|
+
"groups":{
|
|
4
|
+
"item":"item",
|
|
5
|
+
"items":"items",
|
|
6
|
+
},
|
|
7
|
+
"columns":{
|
|
8
|
+
},
|
|
9
|
+
"data":{
|
|
10
|
+
"loading":"Loading",
|
|
11
|
+
"error":"Error",
|
|
12
|
+
},
|
|
13
|
+
"pagination":{
|
|
14
|
+
"page_size":"Page Size",
|
|
15
|
+
"page_title":"Show Page",
|
|
16
|
+
"first":"First",
|
|
17
|
+
"first_title":"First Page",
|
|
18
|
+
"last":"Last",
|
|
19
|
+
"last_title":"Last Page",
|
|
20
|
+
"prev":"Prev",
|
|
21
|
+
"prev_title":"Prev Page",
|
|
22
|
+
"next":"Next",
|
|
23
|
+
"next_title":"Next Page",
|
|
24
|
+
"all":"All",
|
|
25
|
+
"counter":{
|
|
26
|
+
"showing": "Showing",
|
|
27
|
+
"of": "of",
|
|
28
|
+
"rows": "rows",
|
|
29
|
+
"pages": "pages",
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"headerFilters":{
|
|
33
|
+
"default":"filter column...",
|
|
34
|
+
"columns":{}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
37
|
};
|