Wrote tests for i18n
This commit is contained in:
parent
dbc37b177a
commit
280b986898
1 changed files with 29 additions and 28 deletions
|
@ -2,42 +2,43 @@ describe 'utils library', ->
|
||||||
util = require 'lib/utils'
|
util = require 'lib/utils'
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
this.fixture1 = {
|
this.fixture1 =
|
||||||
"text": "G'day, Wizard! Come to practice? Well, let's get started...",
|
"text": "G'day, Wizard! Come to practice? Well, let's get started..."
|
||||||
"i18n": {
|
"i18n":
|
||||||
"es-419": {
|
"es-419":
|
||||||
"text": "¡Buenas, Hechicero! ¿Vienes a practicar? Bueno, empecemos..."
|
"text": "¡Buenas, Hechicero! ¿Vienes a practicar? Bueno, empecemos..."
|
||||||
},
|
"es-ES":
|
||||||
"es-ES": {
|
|
||||||
"text": "¡Buenas Mago! ¿Vienes a practicar? Bien, empecemos..."
|
"text": "¡Buenas Mago! ¿Vienes a practicar? Bien, empecemos..."
|
||||||
},
|
"es":
|
||||||
"es": {
|
|
||||||
"text": "¡Buenas Mago! ¿Vienes a practicar? Muy bien, empecemos..."
|
"text": "¡Buenas Mago! ¿Vienes a practicar? Muy bien, empecemos..."
|
||||||
},
|
"fr":
|
||||||
"fr": {
|
|
||||||
"text": "S'lut, Magicien! Venu pratiquer? Ok, bien débutons..."
|
"text": "S'lut, Magicien! Venu pratiquer? Ok, bien débutons..."
|
||||||
},
|
"pt-BR":
|
||||||
"pt-BR": {
|
|
||||||
"text": "Bom dia, feiticeiro! Veio praticar? Então vamos começar..."
|
"text": "Bom dia, feiticeiro! Veio praticar? Então vamos começar..."
|
||||||
},
|
"de":
|
||||||
"de": {
|
|
||||||
"text": "'N Tach auch, Zauberer! Kommst Du zum Üben? Dann lass uns anfangen..."
|
"text": "'N Tach auch, Zauberer! Kommst Du zum Üben? Dann lass uns anfangen..."
|
||||||
},
|
"tr":
|
||||||
"tr": {
|
|
||||||
"text": "İyi günler, Büyücü! Antremana mı geldin? Güzel, hadi başlayalım..."
|
"text": "İyi günler, Büyücü! Antremana mı geldin? Güzel, hadi başlayalım..."
|
||||||
},
|
"sv":
|
||||||
"sv": {
|
|
||||||
"text": "Godagens, trollkarl! Kommit för att öva? Nå, låt oss börja..."
|
"text": "Godagens, trollkarl! Kommit för att öva? Nå, låt oss börja..."
|
||||||
},
|
"en":
|
||||||
"ex": {
|
|
||||||
"text": "Ohai Magician!"
|
"text": "Ohai Magician!"
|
||||||
}
|
|
||||||
},
|
|
||||||
"sound": {
|
|
||||||
"mp3": "db/level/52740644904ac0411700067c/gday_wizard_come_to_practice.mp3",
|
|
||||||
"ogg": "db/level/52740644904ac0411700067c/gday_wizard_come_to_practice.ogg"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
it 'i18n should find a valid target string', ->
|
it 'i18n should find a valid target string', ->
|
||||||
expect(util.i18n(this.fixture1, 'text', 'sv')).toEqual(this.fixture1.i18n.en.text)
|
expect(util.i18n(this.fixture1, 'text', 'sv')).toEqual(this.fixture1.i18n['sv'].text)
|
||||||
|
expect(util.i18n(this.fixture1, 'test', 'es-ES')).toEqual(this.fixture1.i18n['es-ES'].text)
|
||||||
|
|
||||||
|
it 'i18n picks the correct fallback for a specific language', ->
|
||||||
|
expect(util.i18n(this.fixture1, 'text', 'fr-be')).toEqual(this.fixture1.i18n['fr'].text)
|
||||||
|
|
||||||
|
it 'i18n picks the correct fallback', ->
|
||||||
|
expect(util.i18n(this.fixture1, 'text', 'nl')).toEqual(this.fixture1.i18n['en'].text)
|
||||||
|
expect(util.i18n(this.fixture1, 'text', 'nl', 'de')).toEqual(this.fixture1.i18n['de'].text)
|
||||||
|
|
||||||
|
it 'i18n falls back to the default text, even for other targets (like burb)', ->
|
||||||
|
delete this.fixture1.i18n['en']
|
||||||
|
expect(util.i18n(this.fixture1, 'text', 'en')).toEqual(this.fixture1.text)
|
||||||
|
expect(util.i18n(this.fixture1, 'blurb', 'en')).toEqual(this.fixture1.text)
|
||||||
|
|
||||||
|
it 'i18n can fall forward if a general language is not found', ->
|
||||||
|
expect(util.i18n(this.fixture1, 'text', 'pt')).toEqual(this.fixture1.i18n['pt-BR'].text)
|
Reference in a new issue