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) {
|
initialize: function(container, application) {
|
||||||
// detect browser language
|
// detect browser language
|
||||||
var language = '';
|
var language = '';
|
||||||
|
|
||||||
// have a look if it's already stored in a cookie
|
// have a look if it's already stored in a cookie
|
||||||
var cookie = document.cookie.replace(" ", "").split(";");
|
var cookie = document.cookie.replace(" ", "").split(";");
|
||||||
cookie.forEach(function(t){
|
cookie.forEach(function(t){
|
||||||
|
@ -17,32 +17,32 @@ export default {
|
||||||
language = x[1];
|
language = x[1];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// if not we do it by browser language
|
// if not we do it by browser language
|
||||||
if (language === '') {
|
if (language === '') {
|
||||||
language = (window.navigator.userLanguage || window.navigator.language).split("-")[0];
|
language = (window.navigator.userLanguage || window.navigator.language).split("-")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if language is supported
|
// check if language is supported
|
||||||
if(typeof translations[language] !== "object") {
|
if(typeof translations[language] !== "object") {
|
||||||
language = "en";
|
language = "en";
|
||||||
}
|
}
|
||||||
|
|
||||||
Ember.FEATURES.I18N_TRANSLATE_HELPER_SPAN = false;
|
Ember.FEATURES.I18N_TRANSLATE_HELPER_SPAN = false;
|
||||||
Ember.ENV.I18N_COMPILE_WITHOUT_HANDLEBARS = true;
|
Ember.ENV.I18N_COMPILE_WITHOUT_HANDLEBARS = true;
|
||||||
Ember.I18n.translations = translations[language];
|
Ember.I18n.translations = Ember.copy(translations[language]);
|
||||||
Ember.I18n.locale = language;
|
Ember.I18n.locale = language;
|
||||||
|
|
||||||
// inject into controller
|
// inject into controller
|
||||||
var languageStorage = Ember.Object.extend({
|
var languageStorage = Ember.Object.extend({
|
||||||
selected: language
|
selected: language
|
||||||
});
|
});
|
||||||
container.register('language:current', languageStorage, {singleton: true});
|
container.register('language:current', languageStorage, {singleton: true});
|
||||||
application.inject('controller', 'language', 'language:current');
|
application.inject('controller', 'language', 'language:current');
|
||||||
|
|
||||||
// set moment locale
|
// set moment locale
|
||||||
moment.locale( language );
|
moment.locale( language );
|
||||||
|
|
||||||
// set webshim locale
|
// set webshim locale
|
||||||
webshim.activeLang(language);
|
webshim.activeLang(language);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,7 @@ module('Unit | languages');
|
||||||
// Replace this with your real tests.
|
// Replace this with your real tests.
|
||||||
test('translations are correct', function(assert) {
|
test('translations are correct', function(assert) {
|
||||||
assert.ok(languages);
|
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) {
|
Object.keys(languages).map(function(language) {
|
||||||
if (language !== 'en') {
|
if (language !== 'en') {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
@ -20,7 +16,6 @@ test('translations are correct', function(assert) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
Object.keys(languages.en).map(function(translationKey) {
|
Object.keys(languages.en).map(function(translationKey) {
|
||||||
Object.keys(languages).map(function(language) {
|
Object.keys(languages).map(function(language) {
|
||||||
|
|
Loading…
Reference in a new issue