1. Mathias Panzenböck
  2. JavaScript Transform

Commits

Mathias Panzenböck  committed f1072b4

can pass existing string table to i18n functions

  • Participants
  • Parent commits 757c775
  • Branches default

Comments (0)

Files changed (1)

File lib/i18n.js

View file
  • Ignore whitespace
 "use strict";
 
+var extend = require("extend");
 var Transformer = require("./transformer.js").Transformer;
 var match = require("./patterns.js").PatternHelper;
 var make = require("./nodes.js").NodeHelper;
 
 function getstrings (code, options) {
 	if (!options) options = {};
-	var strings = {};
+	var strings = options.strings || {};
+	var troptions = extend({},options);
+	delete troptions.strings;
 	var has = Object.prototype.hasOwnProperty;
 	new Transformer().on(
 		match.global('_').call(match.string(), match.many()),
 			else {
 				strings[s] = 1;
 			}
-		}).transform(code, options);
+		}).transform(code, troptions);
 	return strings;
 }
 
 function compile (code, options) {
-	var strings = {};
+	if (!options) options = {};
+	var strings = options.strings || {};
+	var troptions = extend({},options);
+	delete troptions.strings;
 	var nextid = 0;
 	var has = Object.prototype.hasOwnProperty;
 	var node = new Transformer().replace(
 				strings[s] = id = '_'+(nextid++);
 			}
 			return make.id('_').get(id);
-		}).transform(code, options);
-	var inverse = {};
-	for (var s in strings) {
-		inverse[strings[s]] = s;
-	}
+		}).transform(code, troptions);
 	return {
-		strings: inverse,
+		strings: strings,
 		code: node
 	};
 }