\
@@ -58,8 +58,6 @@ my.Map = Backbone.I18nView.extend({
// this will be the Leaflet L.Map object (setup below)
this.map = null;
- this.initializeI18n(options.locale);
-
var stateData = _.extend({
geomField: null,
lonField: null,
@@ -97,8 +95,7 @@ my.Map = Backbone.I18nView.extend({
this.menu = new my.MapMenu({
model: this.model,
- state: this.state.toJSON(),
- locale: this.locale
+ state: this.state.toJSON()
});
this.listenTo(this.menu.state, 'change', function() {
self.state.set(self.menu.state.toJSON());
@@ -176,7 +173,8 @@ my.Map = Backbone.I18nView.extend({
// Also sets up the editor fields and the map if necessary.
render: function() {
var self = this;
- var htmls = Mustache.render(this.template, _.extend(this.model.toTemplateJSON(), this.MustacheFormatter()));
+ var tmplData = I18nMessages('recline', recline.View.translations).injectMustache(this.model.toTemplateJSON());
+ var htmls = Mustache.render(this.template, tmplData);
this.$el.html(htmls);
this.$map = this.$el.find('.panel.map');
this.redraw();
@@ -508,7 +506,7 @@ my.Map = Backbone.I18nView.extend({
}
});
-my.MapMenu = Backbone.I18nView.extend({
+my.MapMenu = Backbone.View.extend({
className: 'editor',
template: ' \
@@ -584,7 +582,6 @@ my.MapMenu = Backbone.I18nView.extend({
this.listenTo(this.model.fields, 'change', this.render);
this.state = new recline.Model.ObjectState(options.state);
this.listenTo(this.state, 'change', this.render);
- this.initializeI18n(options.locale);
this.render();
},
@@ -593,7 +590,8 @@ my.MapMenu = Backbone.I18nView.extend({
// Also sets up the editor fields and the map if necessary.
render: function() {
var self = this;
- var htmls = Mustache.render(this.template, _.extend(this.model.toTemplateJSON(), this.MustacheFormatter()));
+ var tmplData = I18nMessages('recline', recline.View.translations).injectMustache(this.model.toTemplateJSON());
+ var htmls = Mustache.render(this.template, tmplData);
this.$el.html(htmls);
if (this._geomReady() && this.model.fields.length){
diff --git a/src/view.multiview.js b/src/view.multiview.js
index 9f0029b2..9187a750 100644
--- a/src/view.multiview.js
+++ b/src/view.multiview.js
@@ -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.I18nView.extend({
+my.MultiView = Backbone.View.extend({
template: ' \
\
\
@@ -131,8 +131,7 @@ my.MultiView = Backbone.I18nView.extend({
initialize: function(options) {
var self = this;
this._setupState(options.state);
- // todo any better idea to pass locale than by initialization? singleton? or does Intl API handle that?
- this.initializeI18n(options.locale);
+ var fmt = I18nMessages('recline', recline.View.translations);
// Hash of 'page' views (i.e. those for whole page) keyed by page name
if (options.views) {
@@ -140,28 +139,28 @@ my.MultiView = Backbone.I18nView.extend({
} else {
this.pageViews = [{
id: 'grid',
- label: this.t('Grid'),
+ label: fmt.t('Grid'),
view: new my.SlickGrid({
model: this.model,
state: this.state.get('view-grid')
})
}, {
id: 'graph',
- label: this.t('Graph'),
+ label: fmt.t('Graph'),
view: new my.Graph({
model: this.model,
state: this.state.get('view-graph')
})
}, {
id: 'map',
- label: this.t('Map'),
+ label: fmt.t('Map'),
view: new my.Map({
model: this.model,
state: this.state.get('view-map')
})
}, {
id: 'timeline',
- label: this.t('Timeline'),
+ label: fmt.t('Timeline'),
view: new my.Timeline({
model: this.model,
state: this.state.get('view-timeline')
@@ -174,17 +173,15 @@ my.MultiView = Backbone.I18nView.extend({
} else {
this.sidebarViews = [{
id: 'filterEditor',
- label: this.t('Filters'),
+ label: fmt.t('Filters'),
view: new my.FilterEditor({
- model: this.model,
- locale: this.locale
+ model: this.model
})
}, {
id: 'fieldsView',
- label: this.t('Fields'),
+ label: fmt.t('Fields'),
view: new my.Fields({
- model: this.model,
- locale: this.locale
+ model: this.model
})
}];
}
@@ -208,7 +205,7 @@ my.MultiView = Backbone.I18nView.extend({
});
this.listenTo(this.model, 'query:done', function() {
self.clearNotifications();
- self.$el.find('.doc-count').text(self.model.recordCount || this.t('Unknown'));
+ self.$el.find('.doc-count').text(self.model.recordCount || fmt.t('Unknown'));
});
this.listenTo(this.model, 'query:fail', function(error) {
self.clearNotifications();
@@ -223,7 +220,7 @@ my.MultiView = Backbone.I18nView.extend({
msg += error.message;
}
} else {
- msg = this.t('backend_error', {}, 'There was an error querying the backend');
+ msg = fmt.t('backend_error', {}, 'There was an error querying the backend');
}
self.notify({message: msg, category: 'error', persist: true});
});
@@ -242,7 +239,7 @@ my.MultiView = Backbone.I18nView.extend({
var tmplData = this.model.toTemplateJSON();
tmplData.views = this.pageViews;
tmplData.sidebarViews = this.sidebarViews;
- tmplData = _.extend(tmplData, this.MustacheFormatter());
+ tmplData = I18nMessages('recline', recline.View.translations).injectMustache(tmplData);
var template = Mustache.render(this.template, tmplData);
this.$el.html(template);
@@ -273,8 +270,7 @@ my.MultiView = Backbone.I18nView.extend({
this.$el.find('.recline-results-info').after(this.pager.el);
this.queryEditor = new recline.View.QueryEditor({
- model: this.model.queryState,
- locale: this.locale
+ model: this.model.queryState
});
this.$el.find('.query-editor-here').append(this.queryEditor.el);
@@ -373,7 +369,6 @@ my.MultiView = Backbone.I18nView.extend({
// now get default data + hash url plus initial state and initial our state object with it
var stateData = _.extend({
- locale: 'en',
query: query,
'view-graph': graphState,
backend: this.model.backend.__type__,
diff --git a/src/view.slickgrid.js b/src/view.slickgrid.js
index e10a8d78..ad6b6bf0 100644
--- a/src/view.slickgrid.js
+++ b/src/view.slickgrid.js
@@ -40,11 +40,10 @@ this.recline.View = this.recline.View || {};
// }
// });
//// NB: you need an explicit height on the element for slickgrid to work
-my.SlickGrid = Backbone.I18nView.extend({
+my.SlickGrid = Backbone.View.extend({
initialize: function(modelEtc) {
var self = this;
this.$el.addClass('recline-slickgrid');
- this.initializeI18n(modelEtc.locale);
// Template for row delete menu , change it if you don't love
this.templates = {
@@ -73,7 +72,7 @@ my.SlickGrid = Backbone.I18nView.extend({
if(this.state.get("gridOptions")
&& this.state.get("gridOptions").enabledAddRow != undefined
&& this.state.get("gridOptions").enabledAddRow == true ){
- this.editor = new my.GridControl({locale: this.locale})
+ this.editor = new my.GridControl()
this.elSidebar = this.editor.$el
this.listenTo(this.editor.state, 'change', function(){
this.model.records.add(new recline.Model.Record())
@@ -104,18 +103,19 @@ my.SlickGrid = Backbone.I18nView.extend({
}, self.state.get('gridOptions'));
// We need all columns, even the hidden ones, to show on the column picker
- var columns = [];
+ var columns = [];
+ var fmt = I18nMessages('recline', recline.View.translations);
// custom formatter as default one escapes html
// plus this way we distinguish between rendering/formatting and computed value (so e.g. sort still works ...)
// row = row index, cell = cell index, value = value, columnDef = column definition, dataContext = full row values
var formatter = function(row, cell, value, columnDef, dataContext) {
if(columnDef.id == "del"){
- var formatted = Mustache.render(self.templates.deleterow, _.extend({}, self.MustacheFormatter()));
+ var formatted = Mustache.render(self.templates.deleterow, fmt.injectMustache({}));
return formatted;
}
if(columnDef.id == "#"){
- var formatted = Mustache.render(self.templates.reorderrows, _.extend({}, self.MustacheFormatter()));
+ var formatted = Mustache.render(self.templates.reorderrows, fmt.injectMustache({}));
return formatted;
}
@@ -133,10 +133,9 @@ my.SlickGrid = Backbone.I18nView.extend({
var validator = function(field) {
return function(value){
if (field.type == "date" && isNaN(Date.parse(value))){
- // todo test translation
return {
valid: false,
- msg: self.t('date_required', {}, "A date is required, check field field-date-format")
+ msg: fmt.t('date_required', {}, "A date is required, check field field-date-format")
};
} else {
return {valid: true, msg :null }
@@ -443,7 +442,7 @@ my.SlickGrid = Backbone.I18nView.extend({
// Add new grid Control to display a new row add menu bouton
// It display a simple side-bar menu ,for user to add new
// row to grid
-my.GridControl= Backbone.I18nView.extend({
+my.GridControl= Backbone.View.extend({
className: "recline-row-add",
// Template for row edit menu , change it if you don't love
template: '
',
@@ -452,16 +451,14 @@ my.GridControl= Backbone.I18nView.extend({
var self = this;
_.bindAll(this, 'render');
this.state = new recline.Model.ObjectState();
- options = options || {};
- this.initializeI18n(options.locale);
-
this.render();
},
render: function() {
var self = this;
- var formatted = Mustache.render(this.template, _.extend({}, this.MustacheFormatter()));
+ var tmplData = I18nMessages('recline', recline.View.translations).injectMustache({});
+ var formatted = Mustache.render(this.template, tmplData);
this.$el.html(formatted);
},
diff --git a/src/widget.fields.js b/src/widget.fields.js
index 4758c927..d3583ad4 100644
--- a/src/widget.fields.js
+++ b/src/widget.fields.js
@@ -22,7 +22,7 @@ this.recline.View = this.recline.View || {};
(function($, my) {
"use strict";
-my.Fields = Backbone.I18nView.extend({
+my.Fields = Backbone.View.extend({
className: 'recline-fields-view',
template: ' \
\
@@ -75,8 +75,6 @@ my.Fields = Backbone.I18nView.extend({
self.render();
});
this.$el.find('.collapse').collapse();
- this.initializeI18n(model.locale);
-
this.render();
},
render: function() {
@@ -89,7 +87,7 @@ my.Fields = Backbone.I18nView.extend({
out.facets = field.facets.toJSON();
tmplData.fields.push(out);
});
- tmplData = _.extend(tmplData, this.MustacheFormatter());
+ var tmplData = I18nMessages('recline', recline.View.translations).injectMustache(tmplData);
var templated = Mustache.render(this.template, tmplData);
this.$el.html(templated);
}
diff --git a/src/widget.filtereditor.js b/src/widget.filtereditor.js
index 4f4a4ebe..8637aac2 100644
--- a/src/widget.filtereditor.js
+++ b/src/widget.filtereditor.js
@@ -6,7 +6,7 @@ this.recline.View = this.recline.View || {};
(function($, my) {
"use strict";
-my.FilterEditor = Backbone.I18nView.extend({
+my.FilterEditor = Backbone.View.extend({
className: 'recline-filter-editor well',
template: ' \
\
@@ -100,12 +100,10 @@ my.FilterEditor = Backbone.I18nView.extend({
'submit form.js-edit': 'onTermFiltersUpdate',
'submit form.js-add': 'onAddFilter'
},
- initialize: function(options) {
+ initialize: function() {
_.bindAll(this, 'render');
this.listenTo(this.model.fields, 'all', this.render);
this.listenTo(this.model.queryState, 'change change:filters:new-blank', this.render);
- this.initializeI18n(options.locale);
-
this.render();
},
render: function() {
@@ -118,10 +116,10 @@ my.FilterEditor = Backbone.I18nView.extend({
});
tmplData.fields = this.model.fields.toJSON();
tmplData.filterRender = function() {
- var filterData = _.extend(this, self.MustacheFormatter());
+ var filterData = I18nMessages('recline', recline.View.translations).injectMustache(this);
return Mustache.render(self.filterTemplates[this.type], filterData);
};
- tmplData = _.extend(tmplData, self.MustacheFormatter());
+ tmplData = I18nMessages('recline', recline.View.translations).injectMustache(tmplData);
var out = Mustache.render(this.template, tmplData);
this.$el.html(out);
},
diff --git a/src/widget.queryeditor.js b/src/widget.queryeditor.js
index be2620d6..9360c914 100644
--- a/src/widget.queryeditor.js
+++ b/src/widget.queryeditor.js
@@ -6,7 +6,7 @@ this.recline.View = this.recline.View || {};
(function($, my) {
"use strict";
-my.QueryEditor = Backbone.I18nView.extend({
+my.QueryEditor = Backbone.View.extend({
className: 'recline-query-editor',
template: ' \