comments: Update comment for zjsunit/i18n.js.

This commit is contained in:
Steve Howell
2019-12-29 12:39:37 +00:00
committed by Tim Abbott
parent 897320b2c4
commit d41f714eff

View File

@@ -1,10 +1,20 @@
exports.t = function (str, context) { exports.t = function (str, context) {
// We are currently assuming that we will receive context in form of a Dict // HAPPY PATH: most translations are a simple string:
// of key value pairs and string will be having substitution for keywords
// like these "__keyword__".
if (context === undefined) { if (context === undefined) {
return 'translated: ' + str; return 'translated: ' + str;
} }
/*
context will be an ordinary JS object like this:
{minutes: minutes.toString()}
This supports use cases like the following:
i18n.t("__minutes__ min to edit", {minutes: minutes.toString()})
We have to munge in the context here.
*/
const keyword_regex = /__(- )?(\w)+__/g; const keyword_regex = /__(- )?(\w)+__/g;
const keys_in_str = str.match(keyword_regex); const keys_in_str = str.match(keyword_regex);
const substitutions = _.map(keys_in_str, function (key) { const substitutions = _.map(keys_in_str, function (key) {