Skip to content
Closed
24 changes: 17 additions & 7 deletions msgfmt:extract/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var checkForUpdates = function(m, force) {

var walker = walk.walk(relUp, {
followLinks: false,
filters: [
filters: [
/\/\.[^\.]+\// // skip .directories (hidden)
]
});
Expand Down Expand Up @@ -211,7 +211,7 @@ var boundCheck = Meteor.bindEnvironment(checkForUpdates);

// https://github.com/meteor/meteor/pull/3704/files
process.on('SIGUSR2', boundCheck); // Meteor < 1.0.4
process.on('SIGHUP', boundCheck); // Meteor >= 1.0.4
process.on('SIGHUP', boundCheck); // Meteor >= 1.0.4
process.on('message', boundCheck); // Meteor >= 1.0.4

// No reason to block startup, we can do update gradually asyncronously
Expand All @@ -238,7 +238,7 @@ Meteor.startup(function() {
});

checkForUpdates();
});
});

/* handler helpers */

Expand All @@ -254,7 +254,7 @@ var lastFile = null;
function logKey(file, key, text, file, line, strings) {
if (strings[key] && strings[key].text != text)
log.warn('{ ' + key + ': "' + text + '" } in '
+ file + ':' + line + ' replaces DUP_KEY\n { '
+ file + ':' + line + ' replaces DUP_KEY { '
+ key + ': "' + strings[key].text + '" } in '
+ strings[key].file + ':' + strings[key].line);

Expand All @@ -266,7 +266,11 @@ function logKey(file, key, text, file, line, strings) {
log.trace(file);
}

log.trace('* ' + key + ': "' + text.replace(/\s+/g, ' ') + '"');
log.trace('* ' + key + ': "' + (text ? text.replace(/\s+/g, ' ') : "NO TEXT") + '"');
}

function checkText(text, key) {
return (text == null || text == '' || text == "''" || text == '"') ? ("<" + key + ">" ) : text;
}

/* handlers */
Expand All @@ -278,12 +282,13 @@ handlers.html = function(file, data, mtime, strings) {
var result, re;

// {{mf "key" 'text' attr1=val1 attr2=val2 etc}}
re = /{{[\s]?mf (['"])(.*?)\1 ?(["'])(.*?)\3(.*?)}}/g;
re = /\{\{[\s]?mf ['"](.*?)['"] ?(["'](.*?)['"])?(.*?)\}\}/g;
while (result = re.exec(data)) {
var key = result[2], text = result[4], attributes = attrDict(result[5]);
var key = result[1], text = result[3], attributes = attrDict(result[4]);
var tpl = /<template .*name=(['"])(.*?)\1.*?>[\s\S]*?$/
.exec(data.substring(0, result.index)); // TODO, optimize
var line = data.substring(0, result.index).split('\n').length;
text = checkText(text, key);
logKey(file, key, text, file, line, strings);
strings[key] = {
key: key,
Expand All @@ -302,6 +307,7 @@ handlers.html = function(file, data, mtime, strings) {
var tpl = /<template .*name=(['"])(.*?)\1.*?>[\s\S]*?$/
.exec(data.substring(0, result.index)); // TODO, optimize
var line = data.substring(0, result.index).split('\n').length;
text = checkText(text, key);
logKey(file, key, text, file, line, strings);
strings[key] = {
key: key,
Expand All @@ -325,6 +331,7 @@ handlers.jade = function(file, data, mtime, strings) {
var tpl = /[\s\S]*template\s*\(\s*name\s*=\s*(['"])(.*?)\1\s*\)[\s\S]*?$/
.exec(data.substring(0, result.index)); // TODO, optimize
var line = data.substring(0, result.index).split('\n').length;
text = checkText(text, key);
logKey(file, key, text, file, line, strings);
strings[key] = {
key: key,
Expand All @@ -343,6 +350,7 @@ handlers.jade = function(file, data, mtime, strings) {
var tpl = /[\s\S]*template\s*\(\s*name\s*=\s*(['"])([^\1]+?)\1\s*\)[\s\S]*?$/
.exec(data.substring(0, result.index)); // TODO, optimize
var line = data.substring(0, result.index).split('\n').length;
text = checkText(text, key);
logKey(file, key, text, file, line, strings);
strings[key] = {
key: key,
Expand Down Expand Up @@ -371,6 +379,7 @@ handlers.js = function(file, data, mtime, strings) {
var func = /[\s\S]*\n*(.*?function.*?\([\s\S]*?\))[\s\S]*?$/
.exec(data.substring(0, result.index));
var line = data.substring(0, result.index).split('\n').length;
text = checkText(text, key);
logKey(file, key, text, file, line, strings);
strings[key] = {
key: key,
Expand Down Expand Up @@ -401,6 +410,7 @@ handlers.coffee = function(file, data, mtime, strings) {
}

var line = data.substring(0, result.index).split('\n').length;
text = checkText(text, key);
logKey(file, key, text, file, line, strings);
strings[key] = {
key: key,
Expand Down
75 changes: 75 additions & 0 deletions msgfmt:ui/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,77 @@
## msgfmt:ui

# Configuration

In order to support following popular routers, please insert following minimal configuration to your application.
Configuration of security is left with you.

# Iron Router

Register router

```javascript
mfPkg.router = Router;
```

Register routes

```javascript
Router.map(function() {
// Main translation page, summary of all language data
this.route('mfTrans', {
path: '/translate',
waitOn: function() {
return Meteor.subscribe('mfStats');
},
});

// Modify translations for a particular language
this.route('mfTransLang', {
path: '/translate/:lang',
waitOn: function() {
Session.set("translationLanguage", this.params.lang);
// Note, this is in ADDITION to the regular mfStrings sub
return [
Meteor.subscribe('mfStrings', [mfPkg.native, this.params.lang], 0, true),
Meteor.subscribe('mfRevisions', this.params.lang, 10)
];
}
});
});
```

# Flow Router

Register router

```javascript
mfPkg.router = FlowRouter;
```

Register routes


```javascript
FlowRouter.route("/translate/:lang", {
action: function(params) {
// hack to pass data to the temaplate
Session.set("translationLanguage", params.lang);
FlowLayout.render("BasicLayout", {main: "mfTransLang"});
},
subscriptions: function(params) {
this.register('strings', Meteor.subscribe('mfStrings', [mfPkg.native, params.lang], 0, true));
this.register('revisions', Meteor.subscribe('mfRevisions', params.lang, 10));
}
});

FlowRouter.route("/translate/", {
action: function(params) {
// hack to pass data to the temaplate
Session.set("translationLanguage", params.lang);
FlowLayout.render("BasicLayout", { main: "mfTrans"});
},
subscriptions: function(params) {
this.register('stats', Meteor.subscribe('mfStats'));
}
});
```
Loading