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 に答える