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