jedified i18n.parts
This commit is contained in:
parent
a5eb07115d
commit
1364589bcb
@ -25,10 +25,13 @@ lib/vendor/jed.js: node_modules
|
|||||||
|
|
||||||
i18n: lib/i18n-strings.js lib/vendor/jed.js
|
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 \
|
for ts in $(ts); do \
|
||||||
echo $$ts; \
|
echo $$ts; \
|
||||||
pogen/pogen.js $$ts > `dirname $$ts`/`basename $$ts .ts`.po; \
|
node pogen/pogen.js $$ts > `dirname $$ts`/`basename $$ts .ts`.po; \
|
||||||
done
|
done
|
||||||
|
|
||||||
for lang in $(langs); do \
|
for lang in $(langs); do \
|
||||||
|
@ -14,36 +14,40 @@
|
|||||||
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
declare var i18n: any;
|
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) {
|
var i18n = <any>function i18n(strings, ...values) {
|
||||||
i18n['init']();
|
init();
|
||||||
//console.log('i18n:', ...strings, ...values)
|
console.log('i18n:', strings[0]);
|
||||||
return i18n['jed'].translate(strings[0]).fetch(...values);
|
return jed.translate(strings[0]).fetch();
|
||||||
//return String.raw(strings, ...values);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
i18n.lang = chrome.i18n.getUILanguage();
|
i18n.lang = chrome.i18n.getUILanguage();
|
||||||
i18n.jed = null;
|
|
||||||
i18n.strings = {};
|
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
|
// Interpolate i8nized values with arbitrary objects and
|
||||||
// return array of strings/objects.
|
// return array of strings/objects.
|
||||||
i18n.parts = function(strings, ...values) {
|
i18n.parts = function(strings, ...values) {
|
||||||
let parts = [];
|
init();
|
||||||
|
let str = '';
|
||||||
for (let i = 0; i < strings.length; i++) {
|
for (let i = 0; i < strings.length; i++) {
|
||||||
parts.push(strings[i]);
|
str += strings[i];
|
||||||
if (i < values.length) {
|
if (i < strings.length - 1) {
|
||||||
parts.push(values[i]);
|
str += '%'+ (i+1) +'$s';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('i18n.parts:', str, ...values[0].children);
|
||||||
return parts;
|
return jed.translate(str).fetch(...values[0].children);
|
||||||
};
|
};
|
||||||
|
@ -59,7 +59,7 @@ export function processFile(sourceFile: ts.SourceFile) {
|
|||||||
let te = <ts.TemplateExpression>node;
|
let te = <ts.TemplateExpression>node;
|
||||||
let textFragments = [te.head.text];
|
let textFragments = [te.head.text];
|
||||||
for (let tsp of te.templateSpans) {
|
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);
|
textFragments.push(tsp.literal.text);
|
||||||
}
|
}
|
||||||
return textFragments.join('');
|
return textFragments.join('');
|
||||||
@ -126,7 +126,7 @@ export function processFile(sourceFile: ts.SourceFile) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(`#: ${sourceFile.fileName}:${lc.line+1}`);
|
console.log(`#: ${sourceFile.fileName}:${lc.line+1}`);
|
||||||
console.log(`#, csharp-format`);
|
console.log(`#, c-format`);
|
||||||
if (parts.length == 1) {
|
if (parts.length == 1) {
|
||||||
console.log(`msgid "${parts[0]}"`);
|
console.log(`msgid "${parts[0]}"`);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user