Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ var compile = (function(){
'__fest_jschars=/' + jschars.source + '/g,' +
'__fest_jschars_test=/' + jschars.source + '/,' +
'__fest_jshash=' + JSON.stringify(jshash) + ',' +
'i18n=typeof __fest_i18n === "undefined" ? function (str) {return str;} : __fest_i18n,' +
'___fest_log_error;' +
(options.mode === 'function' ? 'function __fest_pushstr(_,s){__fest_buf+=s}' : '') +
'if(typeof __fest_error === "undefined"){___fest_log_error = (typeof console !== "undefined" && console.error) ? function(){return Function.prototype.apply.call(console.error, console, arguments)} : function(){};}else{___fest_log_error=__fest_error};' +
Expand Down
38 changes: 37 additions & 1 deletion lib/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,42 @@ function translate(data) {
}
}

function wrap(text) {
var node = stack[stack.length - 1],
parent = stack[stack.length - 2],
regex = /^data\-/,
params = {};

if (!node || node.ns[node.prefix] !== fest_i18n_ns) {
return escapeHTML(text);
}

text = translate_message(new Message(text));
text = 'i18n("' + text + '"';

for (var key in node.attributes) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Специально нет проверки на собственные свойства?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вобще наверно нет, а нужно ?

if (regex.test(key)) {
params[key.replace(regex, '')] = node.attributes[key].value;
}
}

if (Object.keys(params).length) {
text += ',' + JSON.stringify(params);
}

if (node.attributes.context) {
text += ',' + '"' + node.attributes.context.value + '"';
}

text += ')';

if (parent && ['get', 'script', 'value'].indexOf(parent.local) === -1) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот тут я так на глаз накидал теги в которых контентная модель представлена js кодом. Если есть еще какие то блоки то нужно напишите.

text = '<fest:value>' + text + '</fest:value>';
}

return text;
}

parser.onprocessinginstruction = function(instruction){
result += '<?' + instruction.name + ' ' + instruction.body + '?>';
};
Expand Down Expand Up @@ -178,7 +214,7 @@ function translate(data) {
parser.ontext = function(text){
var xml;
closetag();
ontext(text, escapeHTML);
ontext(text, wrap);
};

parser.oncdata = function(text){
Expand Down
71 changes: 0 additions & 71 deletions spec/build.spec.js

This file was deleted.

17 changes: 17 additions & 0 deletions spec/message.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ describe('fest:message', function () {
);
});

it('should support external i18n function', function () {
global.__fest_i18n = function (str) { return str + ' test'; };

expect(
render('templates/message-with-i18n-ns.xml', {}, {
messages: {
'Строка': 'Line'
}
}).contents
).toBe(
'Line test'
);

delete global.__fest_i18n;
});


it('should allow redefine messages via events', function () {
var sourceMap = {
'Логотип {json.name}': '0',
Expand Down
5 changes: 3 additions & 2 deletions spec/templates/message-with-i18n-ns.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
</fest:set>
<fest:get name="block">
{
text: '<i18n:msg>Строка</i18n:msg>'
text: <i18n:msg>Строка</i18n:msg>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот здесь сломана обратная совместимость, но иначе ни как.

}
</fest:get>
</fest:template>

</fest:template>