2020-01-18 10:13:50 +01:00
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import { classNames, tagName } from '@ember-decorators/component';
|
|
|
|
import { computed } from '@ember/object';
|
2018-12-29 01:27:37 +01:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { readOnly } from '@ember/object/computed';
|
|
|
|
import Component from '@ember/component';
|
2016-06-20 19:28:10 +02:00
|
|
|
import localesMeta from 'croodle/locales/meta';
|
2015-11-20 02:18:19 +01:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
@classic
|
|
|
|
@tagName('select')
|
|
|
|
@classNames('language-select')
|
|
|
|
export default class LanguageSelect extends Component {
|
|
|
|
@service
|
|
|
|
i18n;
|
2019-01-20 15:20:54 +01:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
@service
|
|
|
|
moment;
|
2019-01-20 15:20:54 +01:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
@service
|
|
|
|
powerCalendar;
|
2015-11-20 02:18:19 +01:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
@readOnly('i18n.locale')
|
|
|
|
current;
|
|
|
|
|
|
|
|
@computed('i18n.locales')
|
|
|
|
get locales() {
|
2016-01-19 05:46:52 +01:00
|
|
|
let currentLocale = this.get('i18n.locale');
|
2015-12-07 22:21:38 +01:00
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
return this.get('i18n.locales').map(function(locale) {
|
2015-12-07 22:21:38 +01:00
|
|
|
return {
|
|
|
|
id: locale,
|
|
|
|
selected: locale === currentLocale,
|
2016-06-20 19:28:10 +02:00
|
|
|
text: localesMeta[locale]
|
2015-12-07 22:21:38 +01:00
|
|
|
};
|
2015-11-20 02:18:19 +01:00
|
|
|
});
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|
2015-11-20 02:18:19 +01:00
|
|
|
|
|
|
|
change() {
|
2019-05-22 12:29:29 +02:00
|
|
|
let locale = this.element.options[this.element.selectedIndex].value;
|
2018-12-29 20:35:04 +01:00
|
|
|
|
|
|
|
this.i18n.set('locale', locale);
|
|
|
|
this.moment.changeLocale(locale);
|
2019-01-20 15:20:54 +01:00
|
|
|
this.powerCalendar.set('locale', locale);
|
2018-12-29 20:35:04 +01:00
|
|
|
|
|
|
|
if (window.localStorage) {
|
|
|
|
window.localStorage.setItem('locale', locale);
|
|
|
|
}
|
2015-11-20 02:18:19 +01:00
|
|
|
}
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|