Skip to content

Commit 8f98041

Browse files
localization setting add
1 parent 9ae8d97 commit 8f98041

File tree

6 files changed

+70
-6
lines changed

6 files changed

+70
-6
lines changed

example/index.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<script type="text/javascript" src="../source/js/PivotView.js"></script>
1414
<script type="text/javascript" src="../source/js/DataController.js"></script>
1515
<script type="text/javascript" src="../source/js/MDXParser.js"></script>
16+
<script type="text/javascript" src="../source/js/PivotLocale.js"></script>
1617
<script type="text/javascript" src="../source/js/ExcelExport.js"></script>
1718
<!-- endbuild -->
1819
<style>
@@ -95,17 +96,18 @@
9596
}
9697

9798
setup = {
98-
container: document.getElementById("pivot"), // HTMLElement which will contain table.
99-
dataSource: {
99+
container: document.getElementById("pivot") // HTMLElement which will contain table.
100+
//, locale: "en" // language to use (default: browser default or "en")
101+
, dataSource: {
100102
MDX2JSONSource: "http://" + location.hostname + ":57773/SAMPLES",
101103
// MDX2JSON server address
102104
basicMDX: typeof req === "object" ? req.basicMDX : req
103105
//, pivot: "name of data source.pivot" // name of data source to apply pivot rules
104106
//[ , namespace: "SAMPLES" ] // current namespace : default namespace
105107
//[ , username: "USER" ] // user name : default user
106108
//[ , password: "" ] // user password : default password
107-
},
108-
triggers: { //
109+
}
110+
, triggers: { //
109111
// drillDown: function ({Object { level: {number}, mdx: {string} }}) {}
110112
//, drillThrough: function ({Object { level: {number}, mdx: {string} }}) {}
111113
//, back: function ({Object { level: {number} }}) {}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "LightPivotTable",
33
"author": "ZitRo",
4-
"version": "1.0.0-beta.9",
4+
"version": "1.0.0-beta.10",
55
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
66
"main": "test/testServer.js",
77
"repository": {

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Then use global object constructed from <i>LightPivotTable</i>:
3737
```js
3838
var setup = { // Object that contain settings. Any setting may be missed.
3939
container: document.getElementById("pivot") // HTMLElement which will contain table.
40+
[, locale: "en" ] // language to use (default: browser default or "en")
4041
, dataSource: {
4142
MDX2JSONSource: "http://localhost:57772/SAMPLES", // MDX2JSON server address
4243
basicMDX: typeof req === "object" ? req.basicMDX : req

source/js/DataController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ DataController.prototype.resetRawData = function () {
481481
isCaption: true,
482482
source: {},
483483
noDrillDown: true,
484-
value: navigator.language === "ru" ? "Всего" : "Total"
484+
value: pivotLocale.get(0)
485485
};
486486
applyHeaderStyle(summary[i], false);
487487
} else {

source/js/LightPivotTable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ LightPivotTable.prototype.init = function () {
322322
_.pivotView._backClickHandler.call(_.pivotView);
323323
};
324324

325+
if (this.CONFIG["locale"]) { pivotLocale.setLocale(this.CONFIG["locale"]); }
326+
325327
this.refresh();
326328

327329
};

source/js/PivotLocale.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Light pivot localization.
3+
*
4+
* @scope {pivotLocale} - Sets the pivotLocale scope variable.
5+
* @param {string} [locale] - Two-letter language code.
6+
* @constructor
7+
*/
8+
var PivotLocale = function (locale) {
9+
10+
this.LOCALE = "";
11+
12+
this.setLocale(locale || navigator.language);
13+
14+
};
15+
16+
/**
17+
* Editable locales.
18+
*
19+
* @type {{ru: string, en: string, de: string}[]}
20+
*/
21+
PivotLocale.prototype.LOCALES = [
22+
{ "ru": "Всего", "en": "Total", "de": "Summe" }
23+
];
24+
25+
/**
26+
* @param {string} locale - Two-letter code locale.
27+
*/
28+
PivotLocale.prototype.setLocale = function (locale) {
29+
30+
var i, locales = [];
31+
32+
locale = locale.toLowerCase();
33+
34+
if (this.LOCALES[0].hasOwnProperty(locale)) {
35+
this.LOCALE = locale;
36+
} else {
37+
for (i in this.LOCALES[0]) { locales.push(i); }
38+
console.warn(
39+
"LightPivot: locale " + locale + " is not supported. Currently localized: "
40+
+ locales.join(", ") + "."
41+
);
42+
this.LOCALE = "en";
43+
}
44+
45+
};
46+
47+
/**
48+
* Get the localized phrase.
49+
*
50+
* @param {number} index - Index of phrase.
51+
* @returns {string} - Localized string.
52+
*/
53+
PivotLocale.prototype.get = function (index) {
54+
55+
return (this.LOCALES[index] || {})[this.LOCALE] || "{not localized}";
56+
57+
};
58+
59+
var pivotLocale = new PivotLocale();

0 commit comments

Comments
 (0)