From fd2f55f60be1db1ca733cb137ade96807687473a Mon Sep 17 00:00:00 2001 From: Vincent Fiduccia Date: Mon, 24 Apr 2017 17:25:05 -0700 Subject: [PATCH] Fix shift-L for toggling language --- .../container/new-edit/component.js | 2 +- app/components/page-header/component.js | 5 ++++- app/instance-initializers/intl.js | 19 +++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/components/container/new-edit/component.js b/app/components/container/new-edit/component.js index ed12880c3..481c26d1f 100644 --- a/app/components/container/new-edit/component.js +++ b/app/components/container/new-edit/component.js @@ -145,7 +145,7 @@ export default Ember.Component.extend(NewOrEdit, SelectTab, { }); return out; - }.property('service.name','service.secondaryLaunchConfigs.@each.name','intl._locale'), + }.property('service.name','service.secondaryLaunchConfigs.@each.name','intl.locale'), noLaunchConfigsEnabled: function() { return this.get('launchConfigChoices').filterBy('enabled',true).get('length') === 0; diff --git a/app/components/page-header/component.js b/app/components/page-header/component.js index 06c830e93..01fd1a412 100644 --- a/app/components/page-header/component.js +++ b/app/components/page-header/component.js @@ -21,6 +21,7 @@ export default Ember.Component.extend(HoverDropdown, { currentPath : null, // Injections + intl : Ember.inject.service(), projects : Ember.inject.service(), project : Ember.computed.alias('projects.current'), projectId : Ember.computed.alias(`tab-session.${C.TABSESSION.PROJECT}`), @@ -53,6 +54,7 @@ export default Ember.Component.extend(HoverDropdown, { init() { this._super(...arguments); + this.get('intl.locale'); this.set('stacks', this.get('store').all('stack')); this.set('hosts', this.get('store').all('host')); this.set('stackSchema', this.get('store').getById('schema','stack')); @@ -114,7 +116,8 @@ export default Ember.Component.extend(HoverDropdown, { 'stacks.@each.group', `prefs.${C.PREFS.ACCESS_WARNING}`, 'access.enabled', - 'isAdmin' + 'isAdmin', + 'intl.locale' ), // Utilities you can use in the condition() function to decide if an item is shown or hidden, diff --git a/app/instance-initializers/intl.js b/app/instance-initializers/intl.js index 51247925d..4c724e1dc 100644 --- a/app/instance-initializers/intl.js +++ b/app/instance-initializers/intl.js @@ -3,23 +3,26 @@ import missingMessage from 'ui/utils/intl/missing-message'; const { get, makeArray } = Ember; export function initialize(instance) { - var intl = instance.lookup('service:intl'); + let intl = instance.lookup('service:intl'); + let adapter = intl.get('adapter'); - intl.reopen({ - // calling findTranslationByKey with a null key explodes, make it return something - _findTranslationByKey: intl.findTranslationByKey, - findTranslationByKey(key, locales) { - locales = makeArray(locales || get(this, '_locale')); + adapter.reopen({ + _lookup: adapter.lookup, + lookup(locales, key) { + locales = makeArray(locales || get(this, 'locale')); if (locales[0] === 'none') { return missingMessage(key, locales); } else if ( key ) { - return this._findTranslationByKey(...arguments); + return this._lookup(locales, key); }else { - return this._findTranslationByKey('generic.missing', locales); + return this._lookup(locales, 'generic.missing'); } }, + }); + // @TODO use regular t with htmlSafe instead + intl.reopen({ tHtml(key, ...args) { const [ options ] = args; const translation = this.findTranslationByKey(key, options && options.locale);