fix locale storage in cookie

This commit is contained in:
jelhan 2015-12-07 22:21:38 +01:00
parent b33a2f84f2
commit db038b1e57
4 changed files with 21 additions and 21 deletions

View file

@ -1,5 +1,4 @@
import Ember from 'ember';
/* global webshim */
export default Ember.Component.extend({
tagName: 'select',
@ -9,15 +8,19 @@ export default Ember.Component.extend({
current: Ember.computed.readOnly('i18n.locale'),
locales: Ember.computed('i18n.locales', function() {
var currentLocale = this.get('i18n.locale');
return this.get('i18n.locales').map(function (locale) {
return { id: locale, text: locale };
return {
id: locale,
selected: locale === currentLocale,
text: locale
};
});
}),
change() {
var locale = this.$().val();
this.get('i18n').set('locale', locale);
this.get('moment').changeLocale(locale);
webshim.activeLang(locale);
}
});

View file

@ -1,18 +1,4 @@
import Ember from "ember";
/* global moment */
export default Ember.Controller.extend({
i18n: Ember.inject.service(),
languageChanged: function() {
// change language
var language = this.get('i18n.locale');
// save language in cookie
document.cookie="language=" + language + ";" +
// give cookie a lifetime of one year
"max-age=" + 60*60*24*356 + ";";
moment.locale(language);
}.observes('i18n.locale')
});

View file

@ -11,13 +11,24 @@ export default {
i18n.set('locale', locale);
moment.changeLocale(locale);
webshim.activeLang(locale);
i18n.addObserver('locale', i18n, function() {
var locale = this.get('locale');
moment.changeLocale(locale);
webshim.activeLang(locale);
// save selected locale in cookie
document.cookie="language=" + locale + ";" +
// give cookie a lifetime of one year
"max-age=" + 60*60*24*356 + ";";
});
}
};
function getLocale(availableLocales) {
var methods = [
getLocaleByBrowser,
getLocaleFromCookie
getLocaleFromCookie,
getLocaleByBrowser
];
var locale;

View file

@ -1,3 +1,3 @@
{{#each locales as |locale|}}
<option value="{{locale.id}}">{{locale.text}}</option>
<option value="{{locale.id}}" selected={{locale.selected}}>{{locale.text}}</option>
{{/each}}