get-translation
Version:
Effective translation workflow
24 lines (23 loc) • 5.98 kB
JavaScript
define(function() {
function encodeHTMLSource() { var encodeHTMLRules = { "&": "&", "<": "<", ">": ">", '"': '"', "'": ''', "/": '/' }, matchHTML = /&(?!#?w+;)|<|>|"|'|\//g; return function() { return this ? this.replace(matchHTML, function(m) {return encodeHTMLRules[m] || m;}) : this; };};
String.prototype.encodeHTML=encodeHTMLSource();
var tmpl = {};
tmpl['compositeRouter']=function anonymous(it) {
var out='define([\'backbone\',\'jquery\',';var arr1=it.imports;if(arr1){var _import,index=-1,l1=arr1.length-1;while(index<l1){_import=arr1[index+=1];out+='\''+(_import.view.path)+'\',\''+(_import.model.path)+'\'';if(index !== it.imports.length - 1){out+=',';}} } out+='], function(Backbone,$,';var arr2=it.imports;if(arr2){var _import,index=-1,l2=arr2.length-1;while(index<l2){_import=arr2[index+=1];out+=(_import.view.name)+','+(_import.model.name);if(index !== it.imports.length - 1){out+=',';}} } out+=') {var Constructor = Backbone.Router.extend({routes : {';var arr3=it.pages;if(arr3){var page,index=-1,l3=arr3.length-1;while(index<l3){page=arr3[index+=1];out+='\''+(page.path)+'\' : \'compose '+(page.path)+'\'';if(index !== it.pages.length - 1){out+=',';}} } out+='},';var arr4=it.pages;if(arr4){var page,index=-1,l4=arr4.length-1;while(index<l4){page=arr4[index+=1];out+='\'compose '+(page.path)+'\': function() {var _this = this, incorrectRegions = 0, n = 0;app.document.trigger(\'fetchstart\', \''+(page.path)+'\');'+(page.contentScript)+'for(var view in app.views) {if('+(page.noViewsScript)+') {app.views[view].remove();delete app.views[view];if(typeof app.models[view] !== \'undefined\') {Backbone.Relational.store.unregister(app.models[view]);delete app.models[view];}}}},';} } var arr5=it.pages;if(arr5){var page,index=-1,l5=arr5.length-1;while(index<l5){page=arr5[index+=1];out+='\'render '+(page.path)+'\': function() {app.document.trigger(\'renderstart\');if(document.querySelectorAll(\'[data-layout='+(page.layout)+']\').length) {'+(page.renderScript)+'}else {app.$layout.remove();app.$body.append(app.layoutTmpls.'+(page.layout)+'({'+(page.mapScript)+'}));}app.document.trigger(\'renderend\');},';} } out+='});Constructor.prototype.content = {};return Constructor;});';return out;
};
tmpl['contentScript']=function anonymous(it) {
var out='this.should = {};';var arr1=it;if(arr1){var content,index=-1,l1=arr1.length-1;while(index<l1){content=arr1[index+=1];out+='if(typeof app.views.'+(content.model.toLowerCase())+' === \'undefined\' || app.views.'+(content.model.toLowerCase())+'.should(\''+(content.path)+'\') === \'update\') {if(typeof app.views.'+(content.model.toLowerCase())+' === \'undefined\') {if(!document.querySelector(\'[data-content="'+(content.model.toLowerCase())+'"]\')) {this.should[\''+(content.model.toLowerCase())+'\'] = \'update\';}else {this.should[\''+(content.model.toLowerCase())+'\'] = \'keep\';}}else {this.should[\''+(content.model.toLowerCase())+'\'] = app.views.'+(content.model.toLowerCase())+'.should(\''+(content.path)+'\');Backbone.Relational.store.unregister(app.models.'+(content.model.toLowerCase())+');}app.models.'+(content.model.toLowerCase())+' = new '+(content.model)+';app.views.'+(content.model.toLowerCase())+' = new '+(content.view)+'(app.models.'+(content.model.toLowerCase())+');incorrectRegions++;setTimeout(function() {try {app.models.'+(content.model.toLowerCase())+'.fetch({success: function() {_this.content[\''+(content.region)+'\'] = app.views.'+(content.model.toLowerCase())+'.toHTML();if(typeof app.views.'+(content.model.toLowerCase())+'.bindModel === \'function\') {app.views.'+(content.model.toLowerCase())+'.bindModel();}n++;if(n === incorrectRegions) {app.document.trigger(\'fetchend\', \''+(content.path)+'\');_this[\'render '+(content.path)+'\']();}}});}catch(err) {if(err.message === \'A "url" property or function must be specified\') {_this.content[\''+(content.region)+'\'] = app.views.'+(content.model.toLowerCase())+'.toHTML();n++;if(n === incorrectRegions) {app.document.trigger(\'fetchend\', \''+(content.path)+'\');_this[\'render '+(content.path)+'\']();}}else {throw err;}}}, 0);}else if(app.views.'+(content.model.toLowerCase())+'.should(\''+(content.path)+'\') === \'remove\') {app.views.'+(content.model.toLowerCase())+'.hide();}else {app.views.'+(content.model.toLowerCase())+'.show();}';} } return out;
};
tmpl['mapScript']=function anonymous(it) {
var out='';var arr1=it;if(arr1){var content,index=-1,l1=arr1.length-1;while(index<l1){content=arr1[index+=1];out+=(content.region)+' : this.content[\''+(content.model.toLowerCase())+'\']';if(index !== it.length - 1){out+=',';}} } return out;
};
tmpl['noViewsScript']=function anonymous(it) {
var out='';var arr1=it;if(arr1){var view,index=-1,l1=arr1.length-1;while(index<l1){view=arr1[index+=1];out+='view !== \''+(view)+'\'';if(index !== it.length - 1){out+=' && ';}} } return out;
};
tmpl['renderScript']=function anonymous(it) {
var out='';var arr1=it;if(arr1){var content,index=-1,l1=arr1.length-1;while(index<l1){content=arr1[index+=1];out+='app.document.trigger(\'render'+(content.model.toLowerCase())+'start\');try {if(this.should[\''+(content.model.toLowerCase())+'\'] === \'update\') {var $region = document.querySelector(\'[data-region="'+(content.region)+'"]\');$region.innerHTML = this.content[\''+(content.region)+'\'];$region.classList.remove(\'hidden\');}if(app.views.el !== \'<div></div>\') {app.views.'+(content.model.toLowerCase())+'.setElement(\'[data-content="'+(content.model.toLowerCase())+'"]\');}if(!app.views.'+(content.model.toLowerCase())+'.boundDOM) {app.views.'+(content.model.toLowerCase())+'.bindDOM();app.views.'+(content.model.toLowerCase())+'.boundDOM = true;}}catch(err) {throw err;}app.document.trigger(\'render'+(content.model.toLowerCase())+'end\');';} } return out;
};
tmpl['jsonScript']=function anonymous(it) {
var out='<script type="application/json" class="js-json-'+(it.name)+'">'+(it.json)+'</script>';return out;
};
return tmpl;});