aboutsummaryrefslogtreecommitdiff
path: root/extension
diff options
context:
space:
mode:
authortg(x) <*@tg-x.net>2016-02-23 15:58:05 +0100
committertg(x) <*@tg-x.net>2016-02-23 15:58:05 +0100
commit1364589bcb8309c4fc923761712f119f1484e8ff (patch)
tree0e9777795785cc21e954b76d3580082184dff739 /extension
parenta5eb07115dc59782df5a449a615b71526ff76ed6 (diff)
jedified i18n.parts
Diffstat (limited to 'extension')
-rw-r--r--extension/Makefile7
-rw-r--r--extension/lib/i18n.ts40
-rw-r--r--extension/pogen/pogen.ts4
3 files changed, 29 insertions, 22 deletions
diff --git a/extension/Makefile b/extension/Makefile
index c83cc3896..968f8d98c 100644
--- a/extension/Makefile
+++ b/extension/Makefile
@@ -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 \
diff --git a/extension/lib/i18n.ts b/extension/lib/i18n.ts
index c23ab0740..93bf9a622 100644
--- a/extension/lib/i18n.ts
+++ b/extension/lib/i18n.ts
@@ -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);
};
diff --git a/extension/pogen/pogen.ts b/extension/pogen/pogen.ts
index 8122bbfe5..77f7ea3dc 100644
--- a/extension/pogen/pogen.ts
+++ b/extension/pogen/pogen.ts
@@ -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 {