2

例如,我使用catberry-l10n插件,我想像这样定义应用程序的语言:

www.example.com/en
www.example.com/de
www.example.com/ru
4

1 回答 1

2

因此,所描述的方法很容易在您的项目中使用 Catberry 的路由规则并添加LocaleStore从 URI 获取区域设置参数。任何其他商店都可以使用商店数据,而不会影响性能。

例如,您有这样的路由规则:

module.exports = [
  '/:locale[LocaleStore]/somecrazysegment'
];

此外,您还有 LocaleStore:

LocaleStore.prototype.load = function () {
  // here can be a profile's language request or something else
  return this.$context.state.locale;
};

所以,我们有了 LocaleStore,现在我们可以使用它了。

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]
      };
    });
};

之后,您可以像在示例中一样在组件中使用此类数据:

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
         )
       };
   });
};
于 2015-08-14T18:20:03.103 回答