fix side effect in unit tests for languages by only parsing a copy of imported languages object to ember-i18n
This commit is contained in:
parent
82c22824a6
commit
8b74eb7d86
2 changed files with 9 additions and 14 deletions
|
@ -8,7 +8,7 @@ export default {
|
|||
initialize: function(container, application) {
|
||||
// detect browser language
|
||||
var language = '';
|
||||
|
||||
|
||||
// have a look if it's already stored in a cookie
|
||||
var cookie = document.cookie.replace(" ", "").split(";");
|
||||
cookie.forEach(function(t){
|
||||
|
@ -17,32 +17,32 @@ export default {
|
|||
language = x[1];
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// if not we do it by browser language
|
||||
if (language === '') {
|
||||
language = (window.navigator.userLanguage || window.navigator.language).split("-")[0];
|
||||
}
|
||||
|
||||
|
||||
// check if language is supported
|
||||
if(typeof translations[language] !== "object") {
|
||||
language = "en";
|
||||
}
|
||||
|
||||
|
||||
Ember.FEATURES.I18N_TRANSLATE_HELPER_SPAN = false;
|
||||
Ember.ENV.I18N_COMPILE_WITHOUT_HANDLEBARS = true;
|
||||
Ember.I18n.translations = translations[language];
|
||||
Ember.I18n.translations = Ember.copy(translations[language]);
|
||||
Ember.I18n.locale = language;
|
||||
|
||||
|
||||
// inject into controller
|
||||
var languageStorage = Ember.Object.extend({
|
||||
selected: language
|
||||
});
|
||||
container.register('language:current', languageStorage, {singleton: true});
|
||||
application.inject('controller', 'language', 'language:current');
|
||||
|
||||
|
||||
// set moment locale
|
||||
moment.locale( language );
|
||||
|
||||
|
||||
// set webshim locale
|
||||
webshim.activeLang(language);
|
||||
}
|
||||
|
|
|
@ -6,11 +6,7 @@ module('Unit | languages');
|
|||
// Replace this with your real tests.
|
||||
test('translations are correct', function(assert) {
|
||||
assert.ok(languages);
|
||||
/*
|
||||
* test not working
|
||||
* ember-i18n pluralization seems to add another key to languages object
|
||||
* not sure why this modified languages object is retrieved by test
|
||||
* https://github.com/jamesarosen/ember-i18n/tree/810aa7f04b2d30903fa094a5aac10bd4c936fcfe#pluralization
|
||||
|
||||
Object.keys(languages).map(function(language) {
|
||||
if (language !== 'en') {
|
||||
assert.equal(
|
||||
|
@ -20,7 +16,6 @@ test('translations are correct', function(assert) {
|
|||
);
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
Object.keys(languages.en).map(function(translationKey) {
|
||||
Object.keys(languages).map(function(language) {
|
||||
|
|
Loading…
Reference in a new issue