Skip to content

Commit 2096575

Browse files
committed
Set lang for running html samples.
Move localization strings to API viewer/explorer script, fixes #18
1 parent 42cd782 commit 2096575

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

build/localizeFiles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var path = require("path"),
99
module.exports = function(options) {
1010

1111
var processStream = function(file, encoding, next){
12-
var contentsEN, contentsJA, $, jaFile, token,
12+
var contentsEN, contentsJA, jaFile, token,
1313
basePath = path.dirname(file.path),
1414
fileName = path.basename(file.path, path.extname(file.path)),
1515
enStrings, jaStrings,

build/updateResources.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,30 @@ module.exports = function (options) {
3434
};
3535

3636
var processStream = function (file, encoding, next) {
37-
var contents, stream, $, jsStart;
37+
var contents, stream, $, jsStart, $head;
3838

3939
contents = file.contents.toString(encoding);
4040
stream = this;
4141

4242
// https://github.com/cheeriojs/cheerio#loading
4343
$ = file.cheerio = file.cheerio || cheerio.load(contents, { decodeEntities: false });
4444

45+
//set file language
46+
$("html").attr("lang", file.lang);
4547
if (file.lang == "ja") {
4648
// find the first script file /js/infragistics.(core|loader)
4749
jsStart = $("script[src*='%%ignite-ui%%/js/infragistics.']");
4850
if (!jsStart.length) {
4951
throw new Error("Couldn't find core or loader script.");
5052
}
5153
jsStart.eq(0).before("<script src=\"%%ignite-ui%%/js/i18n/infragistics-ja.js\"></script>");
52-
$("head").append("<script src=\"%%ignite-ui%%/js/modules/i18n/regional/infragistics.ui.regional-ja.js\"></script>");
54+
$head = $("head");
55+
$head.append("<script src=\"%%ignite-ui%%/js/modules/i18n/regional/infragistics.ui.regional-ja.js\"></script>");
56+
57+
// ensure charset meta:
58+
if (!$head.find("meta[charset]").length) {
59+
$("<meta>", { charset: "utf-8"}).prependTo($head).attr("charset", "utf-8");
60+
}
5361
}
5462

5563
// script tags

js/apiviewer.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ $.ig = $.ig || {};
66

77
$.extend($.ig, {
88
apiViewer: function () {
9+
var lang = $("html").attr("lang"),
10+
strings = this.locale[ lang ] || this.locale.en;
11+
912
$(".api-explorer,.api-viewer").addClass("api-ui").wrap("<div class='api-container' />");
10-
$(".api-viewer").before("<div class='api-viewer-header api-ui'>$$(API_Viewer)</div>");
11-
$(".api-explorer").before("<div class='api-viewer-header api-ui'>$$(API_Explorer)</div>");
13+
$(".api-viewer").before("<div class='api-viewer-header api-ui'>" + strings.API_Viewer + "</div>");
14+
$(".api-explorer").before("<div class='api-viewer-header api-ui'>" + strings.API_Explorer + "</div>");
1215
$(".api-explorer,.api-viewer").show();
1316
}
1417
});
@@ -23,7 +26,7 @@ $.ig.apiViewer.prototype = {
2326
this._prevCount = 1;
2427
$(_$select).prepend("<div id='firstRow' class='api-row'>" + content + "</div>");
2528
/* OK 7/1/2013 145828 - This causes an exception in the ui-min when it is in an IFrame (jsFiddle) */
26-
try{
29+
try {
2730
$("#firstRow").show("blind", 200, function () {
2831
$(this).animate({ backgroundColor: "#FFFFFF" }, 500, function () {
2932
$(this).removeAttr("id");
@@ -43,5 +46,15 @@ $.ig.apiViewer.prototype = {
4346
}
4447

4548
this._prevContent = content;
49+
},
50+
locale: {
51+
en: {
52+
"API_Viewer": "API Viewer",
53+
"API_Explorer": "API Explorer"
54+
},
55+
ja: {
56+
"API_Viewer": "API ビューアー",
57+
"API_Explorer": "API エクスプローラー"
58+
}
4659
}
4760
}

0 commit comments

Comments
 (0)