I18n support for reclin based on (backbone+moustache first draft. #459 https://github.com/yahoo/intl-messageformat/issues/145
This commit is contained in:
17
src/i18n/pl.js
Normal file
17
src/i18n/pl.js
Normal file
@@ -0,0 +1,17 @@
|
||||
this.recline = this.recline || {};
|
||||
this.recline.View = this.recline.View || {};
|
||||
this.recline.View.translations = this.recline.View.translations || {};
|
||||
|
||||
this.recline.View.translations['pl'] = {
|
||||
'Grid': 'Tabela',
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
//(function(v) {
|
||||
// "use strict";
|
||||
//
|
||||
//
|
||||
//
|
||||
//})(recline.t);
|
||||
//
|
||||
52
src/i18n/view.i18n.js
Normal file
52
src/i18n/view.i18n.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/*jshint multistr:true */
|
||||
|
||||
Backbone.I18nView = Backbone.View.extend({
|
||||
locale: 'en',
|
||||
initialize: function() {
|
||||
console.log("Call on me");
|
||||
// TODO implement cache
|
||||
//memoizeFormatConstructor(Intl.NumberFormat).getNumberFormat();
|
||||
},
|
||||
t: function(key, values = {}, defaultMessage = null) {
|
||||
// get the message from current locale
|
||||
var msg = recline.View.translations['pl'][key];
|
||||
|
||||
// fallback to key or default message if no translation is defined
|
||||
if (msg == null) {
|
||||
console.warn("Missing locale for " + "pl" + "." + key); // TODO when dfault set and it's default locale then be quiet
|
||||
msg = defaultMessage;
|
||||
}
|
||||
if (msg == null) { msg = key; }
|
||||
|
||||
// TODO test fallback to key
|
||||
// TODO test fallback to default message
|
||||
// TODO test overriding messages in external apps
|
||||
// TODO i18n documentation
|
||||
|
||||
var mf = new IntlMessageFormat(msg, 'pl');
|
||||
return mf.format(values);
|
||||
},
|
||||
MustacheFormatter: function() {
|
||||
var property_formatter = new Proxy({}, {
|
||||
get(target, name) {
|
||||
// todo implement formatting
|
||||
return "key: " + name;
|
||||
},
|
||||
has(target, prop) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
var section_formatter = function() {
|
||||
return function (text, render) {
|
||||
// todo implement formatting
|
||||
return "<b>" + render(text) + "</b>";
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
't': property_formatter,
|
||||
'trans': section_formatter
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -94,7 +94,7 @@ this.recline.View = this.recline.View || {};
|
||||
// of views in use -- e.g. those specified by the views argument -- but instead
|
||||
// expect either that the default views are fine or that the client to have
|
||||
// initialized the MultiView with the relevant views themselves.
|
||||
my.MultiView = Backbone.View.extend({
|
||||
my.MultiView = Backbone.I18nView.extend({
|
||||
template: ' \
|
||||
<div class="recline-data-explorer"> \
|
||||
<div class="alert-messages"></div> \
|
||||
@@ -108,6 +108,8 @@ my.MultiView = Backbone.View.extend({
|
||||
</div> \
|
||||
</div> \
|
||||
<div class="recline-results-info"> \
|
||||
{{t.num_records}} -> t + getattr \
|
||||
{{#trans}}<span class="doc-count">{{recordCount}}</span> records{{/trans}} -- \
|
||||
<span class="doc-count">{{recordCount}}</span> records\
|
||||
</div> \
|
||||
<div class="menu-right"> \
|
||||
@@ -138,28 +140,28 @@ my.MultiView = Backbone.View.extend({
|
||||
} else {
|
||||
this.pageViews = [{
|
||||
id: 'grid',
|
||||
label: 'Grid',
|
||||
label: this.t('Grid'),
|
||||
view: new my.SlickGrid({
|
||||
model: this.model,
|
||||
state: this.state.get('view-grid')
|
||||
})
|
||||
}, {
|
||||
id: 'graph',
|
||||
label: 'Graph',
|
||||
label: this.t('Graph'),
|
||||
view: new my.Graph({
|
||||
model: this.model,
|
||||
state: this.state.get('view-graph')
|
||||
})
|
||||
}, {
|
||||
id: 'map',
|
||||
label: 'Map',
|
||||
label: this.t('Map'),
|
||||
view: new my.Map({
|
||||
model: this.model,
|
||||
state: this.state.get('view-map')
|
||||
})
|
||||
}, {
|
||||
id: 'timeline',
|
||||
label: 'Timeline',
|
||||
label: this.t('Timeline'),
|
||||
view: new my.Timeline({
|
||||
model: this.model,
|
||||
state: this.state.get('view-timeline')
|
||||
@@ -238,6 +240,7 @@ my.MultiView = Backbone.View.extend({
|
||||
var tmplData = this.model.toTemplateJSON();
|
||||
tmplData.views = this.pageViews;
|
||||
tmplData.sidebarViews = this.sidebarViews;
|
||||
tmplData = _.extend(tmplData, this.MustacheFormatter());
|
||||
var template = Mustache.render(this.template, tmplData);
|
||||
this.$el.html(template);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user