Closed dschewchenko closed 9 years ago
Could you describe an example?
www.example.com/en www.example.com/ru
Usualy priority of language is: 1 uri 2 cookie 3 browser language
Probably it's not a good idea to force everyone implement language switching like that. Because a lot of people use different approaches doing that. For example,
.com .ru .uk
us.domain.org
, ru.domain.org
So, the approach you described is very easy to implement in your project using Catberry's routing rules and adding LocaleStore
that takes locale parameter from the URI. The store data can be used by any other stores without performance impact.
For example, you have such route rule:
module.exports = [
'/:locale[LocaleStore]/somecrazysegment'
];
Also, you have LocaleStore:
LocaleStore.prototype.load = function () {
// here can be a profile's language request or something else
return this.$context.state.locale;
};
So, we have LocaleStore and now we can use it.
SomeStore.prototype.load = function () {
return Promise.all([
this.$context.getStoreData('LocaleStore'),
this._uhr.get('http://api.some.org/data')
])
.then(function (results) {
return {
locale: results[0],
obj: results[1]
};
});
};
After that, you can use such data in your component like it was in the example:
Component.prototype.render = function () {
var self = this;
return this.$context.getStoreData()
.then(function (data) {
return {
localizedEat: self._l10n.get(data.locale, 'EAT'),
localizedApple: util.format(
self._l10n.pluralize(data.locale, 'APPLE', data.obj.appleCount),
appleCount
)
};
});
};
Oh, thanx for fast and full answer )) And I have small question about catberry. How I can to implement Accordion using my own library and catberrys events 'autobinder'?
P.S. I think that You are working on very fantastic and perspective project
This question is kinda offtop here.
You can use manual event listener adding in bind/unbind
methods of any component. Just wrap your Accordion with the Catberry component and implement everything you need in bind/unbind methods.
For example, there is an answer how to use jQuery with Catberry here.
Big thanx :) If I can, I will help You
Hello What about setting/getting language by uri segment?