Skip to content

Commit

Permalink
localization setting add
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed Jan 30, 2015
1 parent 9ae8d97 commit 8f98041
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 6 deletions.
10 changes: 6 additions & 4 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script type="text/javascript" src="../source/js/PivotView.js"></script>
<script type="text/javascript" src="../source/js/DataController.js"></script>
<script type="text/javascript" src="../source/js/MDXParser.js"></script>
<script type="text/javascript" src="../source/js/PivotLocale.js"></script>
<script type="text/javascript" src="../source/js/ExcelExport.js"></script>
<!-- endbuild -->
<style>
Expand Down Expand Up @@ -95,17 +96,18 @@
}

setup = {
container: document.getElementById("pivot"), // HTMLElement which will contain table.
dataSource: {
container: document.getElementById("pivot") // HTMLElement which will contain table.
//, locale: "en" // language to use (default: browser default or "en")
, dataSource: {
MDX2JSONSource: "http://" + location.hostname + ":57773/SAMPLES",
// MDX2JSON server address
basicMDX: typeof req === "object" ? req.basicMDX : req
//, pivot: "name of data source.pivot" // name of data source to apply pivot rules
//[ , namespace: "SAMPLES" ] // current namespace : default namespace
//[ , username: "USER" ] // user name : default user
//[ , password: "" ] // user password : default password
},
triggers: { //
}
, triggers: { //
// drillDown: function ({Object { level: {number}, mdx: {string} }}) {}
//, drillThrough: function ({Object { level: {number}, mdx: {string} }}) {}
//, back: function ({Object { level: {number} }}) {}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "LightPivotTable",
"author": "ZitRo",
"version": "1.0.0-beta.9",
"version": "1.0.0-beta.10",
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
"main": "test/testServer.js",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Then use global object constructed from <i>LightPivotTable</i>:
```js
var setup = { // Object that contain settings. Any setting may be missed.
container: document.getElementById("pivot") // HTMLElement which will contain table.
[, locale: "en" ] // language to use (default: browser default or "en")
, dataSource: {
MDX2JSONSource: "http://localhost:57772/SAMPLES", // MDX2JSON server address
basicMDX: typeof req === "object" ? req.basicMDX : req
Expand Down
2 changes: 1 addition & 1 deletion source/js/DataController.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ DataController.prototype.resetRawData = function () {
isCaption: true,
source: {},
noDrillDown: true,
value: navigator.language === "ru" ? "Всего" : "Total"
value: pivotLocale.get(0)
};
applyHeaderStyle(summary[i], false);
} else {
Expand Down
2 changes: 2 additions & 0 deletions source/js/LightPivotTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ LightPivotTable.prototype.init = function () {
_.pivotView._backClickHandler.call(_.pivotView);
};

if (this.CONFIG["locale"]) { pivotLocale.setLocale(this.CONFIG["locale"]); }

this.refresh();

};
59 changes: 59 additions & 0 deletions source/js/PivotLocale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Light pivot localization.
*
* @scope {pivotLocale} - Sets the pivotLocale scope variable.
* @param {string} [locale] - Two-letter language code.
* @constructor
*/
var PivotLocale = function (locale) {

this.LOCALE = "";

this.setLocale(locale || navigator.language);

};

/**
* Editable locales.
*
* @type {{ru: string, en: string, de: string}[]}
*/
PivotLocale.prototype.LOCALES = [
{ "ru": "Всего", "en": "Total", "de": "Summe" }
];

/**
* @param {string} locale - Two-letter code locale.
*/
PivotLocale.prototype.setLocale = function (locale) {

var i, locales = [];

locale = locale.toLowerCase();

if (this.LOCALES[0].hasOwnProperty(locale)) {
this.LOCALE = locale;
} else {
for (i in this.LOCALES[0]) { locales.push(i); }
console.warn(
"LightPivot: locale " + locale + " is not supported. Currently localized: "
+ locales.join(", ") + "."
);
this.LOCALE = "en";
}

};

/**
* Get the localized phrase.
*
* @param {number} index - Index of phrase.
* @returns {string} - Localized string.
*/
PivotLocale.prototype.get = function (index) {

return (this.LOCALES[index] || {})[this.LOCALE] || "{not localized}";

};

var pivotLocale = new PivotLocale();

0 comments on commit 8f98041

Please sign in to comment.