2017-02-08 8 views
1

iは燃えさし-I18Nと、次の問題があります。エラー:不明な注入を注入しようとすると:「サービス:I18N」

Error: Attempting to inject an unknown injection: 'service:i18n' 
at Registry.validateInjections (ember.debug.js:2303) 
at ember.debug.js:1538 
at runInDebug (ember.debug.js:5813) 
at Object.runInDebug (ember.debug.js:17396) 
at instantiate (ember.debug.js:1532) 
at lookup (ember.debug.js:1385) 
at Container.lookup (ember.debug.js:1304) 
at Class.lookup (ember.debug.js:32564) 
at Class._internalGetHandler (router-ext.js:107) 
at Class._getHandlerForEngine (router-ext.js:84) 

私は燃えさしエンジンで燃えさし - 国際化プラグインを使用します。私の国際化初期化子addon/instance-initializers/i18n.js:私のインデックスルート(routes/index.js)で

export default { 
name: 'i18n', 

initialize: function(applicationInstance) { 
    const i18nService = applicationInstance.lookup('service:i18n'); 
    i18nService.set('defaultLocale', window.I18n.defaultLocale); 
    i18nService.set('locale', window.I18n.locale); 
} 
}; 

iは、次のコードを持っている:

import Ember from 'ember'; 

export default Ember.Route.extend({ 
i18n: Ember.inject.service(), 

actions: { 
    didTransition() { 
     Ember.run.scheduleOnce('afterRender', this, function() { 
      console.log(this.get('i18n').t('error_empty_user_data')); 
      // .... 
     }); 
    } 
} 
}); 

にはどうすれば国際化サービスを宣言することができますか?

ember-18n 4.5.0バージョンと2.10.0 ember-cliバージョンを使用します。

答えて

1

初期化子は、i18nの後に実行する必要があります。

export default { 
    name: 'i18n', 
    after: ['ember-i18n'], 

    initialize: function(applicationInstance) { 
    const i18nService = applicationInstance.lookup('service:i18n'); 
    i18nService.set('defaultLocale', window.I18n.defaultLocale); 
    i18nService.set('locale', window.I18n.locale); 
    } 
}; 
関連する問題