#459 simple cache
This commit is contained in:
parent
a4c3cae47e
commit
0a8994cf1c
@ -48,8 +48,6 @@
|
||||
<script type="text/javascript" src="{{page.root}}vendor/timeline/js/timeline.js"></script>
|
||||
|
||||
<script type="text/javascript" src="{{page.root}}node_modules/intl-messageformat/dist/intl-messageformat-with-locales.min.js"></script>
|
||||
<script type="module" src="{{page.root}}node_modules/intl-format-cache/lib/memoizer.js"></script>
|
||||
|
||||
|
||||
<!--[if lte IE 7]>
|
||||
<script language="javascript" type="text/javascript" src="{{page.root}}vendor/json/json2.js"></script>
|
||||
|
||||
@ -64,12 +64,14 @@ var createMultiView = function(dataset, state) {
|
||||
$el.appendTo(window.explorerDiv);
|
||||
|
||||
// customize the subviews for the MultiView
|
||||
var locale = 'en';
|
||||
var views = [
|
||||
{
|
||||
id: 'grid',
|
||||
label: 'Grid',
|
||||
view: new recline.View.SlickGrid({
|
||||
model: dataset,
|
||||
locale: locale,
|
||||
state: {
|
||||
gridOptions: {
|
||||
editable: true,
|
||||
@ -93,15 +95,16 @@ var createMultiView = function(dataset, state) {
|
||||
id: 'graph',
|
||||
label: 'Graph',
|
||||
view: new recline.View.Graph({
|
||||
model: dataset
|
||||
|
||||
model: dataset,
|
||||
locale: locale
|
||||
})
|
||||
},
|
||||
{
|
||||
id: 'map',
|
||||
label: 'Map',
|
||||
view: new recline.View.Map({
|
||||
model: dataset
|
||||
model: dataset,
|
||||
locale: locale
|
||||
})
|
||||
}
|
||||
];
|
||||
@ -110,7 +113,7 @@ var createMultiView = function(dataset, state) {
|
||||
model: dataset,
|
||||
el: $el,
|
||||
state: state,
|
||||
locale: 'pl',
|
||||
locale: locale,
|
||||
views: views
|
||||
});
|
||||
return multiView;
|
||||
|
||||
@ -25,8 +25,7 @@
|
||||
"jquery": ">=1.6",
|
||||
"mustache": ">=0.5.2",
|
||||
"underscore": ">=1.0",
|
||||
"intl-messageformat": "1.3.x",
|
||||
"intl-format-cache": "2.0.x"
|
||||
"intl-messageformat": "1.3.x"
|
||||
},
|
||||
"homepage": "http://reclinejs.com/",
|
||||
"keywords": [
|
||||
|
||||
@ -5,12 +5,12 @@
|
||||
Backbone.I18nView = Backbone.View.extend({
|
||||
defaultLocale: 'en',
|
||||
locale: 'en',
|
||||
cache: {},
|
||||
initializeI18n: function(locale, appHardcodedLocale) {
|
||||
this.defaultLocale = appHardcodedLocale || 'en';
|
||||
this.locale = locale || this.defaultLocale;
|
||||
|
||||
// TODO implement cache
|
||||
//memoizeFormatConstructor(Intl.NumberFormat).getNumberFormat();
|
||||
this.cache[this.locale] = {};
|
||||
},
|
||||
|
||||
formatMessage(key, values) {
|
||||
@ -41,8 +41,11 @@ Backbone.I18nView = Backbone.View.extend({
|
||||
// TODO i18n documentation
|
||||
|
||||
try {
|
||||
var mf = new IntlMessageFormat(msg, 'pl');
|
||||
var formatted = mf.format(values);
|
||||
var formatter = this.cache[this.locale][msg];
|
||||
if (formatter === undefined) {
|
||||
this.cache[this.locale][msg] = formatter = new IntlMessageFormat(msg, this.locale);
|
||||
}
|
||||
var formatted = formatter.format(values);
|
||||
|
||||
return formatted;
|
||||
} catch (e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user