jedified i18n.parts

This commit is contained in:
tg(x) 2016-02-23 15:58:05 +01:00
parent a5eb07115d
commit 1364589bcb
3 changed files with 29 additions and 22 deletions

View File

@ -25,10 +25,13 @@ lib/vendor/jed.js: node_modules
i18n: lib/i18n-strings.js lib/vendor/jed.js
pogen: $(ts) node_modules
pogen/pogen.js: pogen/pogen.ts pogen/tsconfig.json node_modules
cd pogen; ../$(tsc)
pogen: $(ts) pogen/pogen.js node_modules
for ts in $(ts); do \
echo $$ts; \
pogen/pogen.js $$ts > `dirname $$ts`/`basename $$ts .ts`.po; \
node pogen/pogen.js $$ts > `dirname $$ts`/`basename $$ts .ts`.po; \
done
for lang in $(langs); do \

View File

@ -14,36 +14,40 @@
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/
"use strict";
declare var i18n: any;
var jed;
function init () {
if ('object' != typeof jed) {
if (!(i18n.lang in i18n.strings)) {
i18n.lang = 'en-US';
}
jed = new window['Jed'] (i18n.strings[i18n.lang]);
}
}
var i18n = <any>function i18n(strings, ...values) {
i18n['init']();
//console.log('i18n:', ...strings, ...values)
return i18n['jed'].translate(strings[0]).fetch(...values);
//return String.raw(strings, ...values);
init();
console.log('i18n:', strings[0]);
return jed.translate(strings[0]).fetch();
};
i18n.lang = chrome.i18n.getUILanguage();
i18n.jed = null;
i18n.strings = {};
i18n.init = function() {
if (null == i18n.jed) {
i18n.jed = new window['Jed'] (i18n.strings[i18n.lang]);
}
}
// Interpolate i8nized values with arbitrary objects and
// return array of strings/objects.
i18n.parts = function(strings, ...values) {
let parts = [];
init();
let str = '';
for (let i = 0; i < strings.length; i++) {
parts.push(strings[i]);
if (i < values.length) {
parts.push(values[i]);
str += strings[i];
if (i < strings.length - 1) {
str += '%'+ (i+1) +'$s';
}
}
return parts;
console.log('i18n.parts:', str, ...values[0].children);
return jed.translate(str).fetch(...values[0].children);
};

View File

@ -59,7 +59,7 @@ export function processFile(sourceFile: ts.SourceFile) {
let te = <ts.TemplateExpression>node;
let textFragments = [te.head.text];
for (let tsp of te.templateSpans) {
textFragments.push(`{${(textFragments.length-1)/2}}`);
textFragments.push(`%${(textFragments.length-1)/2+1}$s`);
textFragments.push(tsp.literal.text);
}
return textFragments.join('');
@ -126,7 +126,7 @@ export function processFile(sourceFile: ts.SourceFile) {
}
}
console.log(`#: ${sourceFile.fileName}:${lc.line+1}`);
console.log(`#, csharp-format`);
console.log(`#, c-format`);
if (parts.length == 1) {
console.log(`msgid "${parts[0]}"`);
} else {