2

I'm using Angular-material and I18next. Here is my simple example :

<md-select ng-init="val='en'" ng-model="val">
    <md-option ng-value="en">{{'en' | i18next}}</md-option>
    <md-option ng-value="de">{{'de' | i18next}}</md-option>
</md-select>

The select title is initialized with 'en' and not 'English'. But as soon as I select an other value the correct internationnalized value appears as the new select title.

Any idea how to get the select element displaying the internationnalized value from its initialization ?

Thanks, Max

N.B. if I initializes directly with 'English' or any other value different than the values in the options, the select element does not get initialized at all.

Update: It looks like the md-select element title is initialized before the md-option elements inner values are internationnalized. I have no idea how to solve this.

4

1 回答 1

1

那是旧 angular-material.js 中的错误,您指的是Github 问题,它已在较新版本中得到解决。

尝试将您的 angular-material.js 更新为最新(版本 1.3.6)将正确选择该值。

HTML

<md-select ng-init="val='en'" ng-model="val">
    <md-option ng-value="en">{{'en' | i18next}}</md-option>
    <md-option ng-value="de">{{'de' | i18next}}</md-option>
</md-select>

工作Plunkr

更新

为了使用过滤器下拉预选值,i18next您需要将 useLocalStorage 选项设置为 true 以保留所有文件,例如“useLocalStorage:true”,

配置

app.config(['$i18nextProvider',
  function($i18nextProvider) {
    $i18nextProvider.options = {
      fallbackLng: 'en',
      useCookie: true,
      useLocalStorage: true, //set to true
      resGetPath: 'i18n-__lng__.json',
      lngWhitelist: ['en', 'de'],
      preload: ['en', 'de']
    };
  }
]);

更新了 Plunkr

希望这会对你有所帮助,谢谢。

于 2015-03-07T12:45:26.440 回答