Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added js/fc/nls/templates.js and modified template plugin to also loc…

…alize.
  • Loading branch information...
commit a64b158a071ad24bb90ce79b7f78c8e6d3107c8a 1 parent b7b9971
@toolness toolness authored
Showing with 36 additions and 5 deletions.
  1. +24 −0 js/fc/nls/templates.js
  2. +12 −5 js/require-plugins/template.js
View
24 js/fc/nls/templates.js
@@ -0,0 +1,24 @@
+define([
+ "inline-l10n"
+], function(InlineL10n) {
+ var root = {};
+ if (typeof(document) == "undefined") {
+ // We're running in node. Parse all inline l10n strings out
+ // of all templates.
+ var fs = require('fs');
+ fs.readdirSync('templates').forEach(function(filename) {
+ var content = fs.readFileSync('templates/' + filename, 'utf8');
+ var defaultValues = InlineL10n.parse(content);
+ for (var key in defaultValues) {
+ var value = defaultValues[key];
+ if (key in root && root[key] != value)
+ throw new Error("conflicting definitions for key: " + key);
+ root[key] = value;
+ }
+ });
+ }
+ return {
+ description: "Strings for the UI defined in template files.",
+ root: root
+ };
+});
View
17 js/require-plugins/template.js
@@ -1,5 +1,11 @@
// This is a simple RequireJS plugin that loads an underscore.js template.
-define(["module", "text", "underscore"], function (module, text, _) {
+define([
+ "module",
+ "text",
+ "underscore",
+ "inline-l10n",
+ "i18n!fc/nls/templates"
+], function (module, text, _, InlineL10n, i18nBundle) {
var buildMap = {},
masterConfig = module.config();
@@ -10,10 +16,10 @@ define(["module", "text", "underscore"], function (module, text, _) {
text.get(url, function (data) {
var template;
if (config.isBuild) {
- template = buildMap[name] = "_.template(" + JSON.stringify(data) +
- ")";
+ template = buildMap[name] = "_.template(InlineL10n(" +
+ JSON.stringify(data) + ", i18nBundle))";
} else {
- template = _.template(data);
+ template = _.template(InlineL10n(data, i18nBundle));
}
onLoad(template);
@@ -23,7 +29,8 @@ define(["module", "text", "underscore"], function (module, text, _) {
if (buildMap[moduleName]) {
var content = buildMap[moduleName];
write.asModule(pluginName + "!" + moduleName,
- "define(['underscore'], function (_) { \n return " + content +
+ "define(['underscore', 'inline-l10n', 'i18n!fc/nls/templates'], " +
+ "function (_, InlineL10n, i18nBundle) { \n return " + content +
";});\n");
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.