2014-03-12 15:30:56 -04:00
|
|
|
describe 'utils library', ->
|
2014-03-12 17:48:27 -04:00
|
|
|
util = require 'lib/utils'
|
2014-03-12 15:30:56 -04:00
|
|
|
|
|
|
|
beforeEach ->
|
2014-03-12 19:11:01 -04:00
|
|
|
this.fixture1 =
|
|
|
|
"text": "G'day, Wizard! Come to practice? Well, let's get started..."
|
2014-03-12 20:07:36 -04:00
|
|
|
"blurb": "G'day"
|
2014-03-12 19:11:01 -04:00
|
|
|
"i18n":
|
|
|
|
"es-419":
|
2014-03-12 15:30:56 -04:00
|
|
|
"text": "¡Buenas, Hechicero! ¿Vienes a practicar? Bueno, empecemos..."
|
2014-03-12 19:11:01 -04:00
|
|
|
"es-ES":
|
2014-03-12 15:30:56 -04:00
|
|
|
"text": "¡Buenas Mago! ¿Vienes a practicar? Bien, empecemos..."
|
2014-03-12 19:11:01 -04:00
|
|
|
"es":
|
2014-03-12 15:30:56 -04:00
|
|
|
"text": "¡Buenas Mago! ¿Vienes a practicar? Muy bien, empecemos..."
|
2014-03-12 19:11:01 -04:00
|
|
|
"fr":
|
2014-03-12 15:30:56 -04:00
|
|
|
"text": "S'lut, Magicien! Venu pratiquer? Ok, bien débutons..."
|
2014-03-12 19:11:01 -04:00
|
|
|
"pt-BR":
|
2014-03-12 15:30:56 -04:00
|
|
|
"text": "Bom dia, feiticeiro! Veio praticar? Então vamos começar..."
|
2014-03-12 19:47:08 -04:00
|
|
|
"en":
|
|
|
|
"text": "Ohai Magician!"
|
2014-03-12 19:11:01 -04:00
|
|
|
"de":
|
2014-03-12 15:30:56 -04:00
|
|
|
"text": "'N Tach auch, Zauberer! Kommst Du zum Üben? Dann lass uns anfangen..."
|
2014-03-12 19:11:01 -04:00
|
|
|
"sv":
|
2014-03-12 15:30:56 -04:00
|
|
|
"text": "Godagens, trollkarl! Kommit för att öva? Nå, låt oss börja..."
|
2014-03-12 19:47:08 -04:00
|
|
|
|
2014-03-12 15:30:56 -04:00
|
|
|
|
|
|
|
it 'i18n should find a valid target string', ->
|
2014-03-12 19:11:01 -04:00
|
|
|
expect(util.i18n(this.fixture1, 'text', 'sv')).toEqual(this.fixture1.i18n['sv'].text)
|
2014-03-12 19:47:08 -04:00
|
|
|
expect(util.i18n(this.fixture1, 'text', 'es-ES')).toEqual(this.fixture1.i18n['es-ES'].text)
|
2014-03-12 19:11:01 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2014-03-12 19:47:08 -04:00
|
|
|
it 'i18n falls back to the default text, even for other targets (like blurb)', ->
|
2014-03-12 19:11:01 -04:00
|
|
|
delete this.fixture1.i18n['en']
|
|
|
|
expect(util.i18n(this.fixture1, 'text', 'en')).toEqual(this.fixture1.text)
|
2014-03-12 20:07:36 -04:00
|
|
|
expect(util.i18n(this.fixture1, 'blurb', 'en')).toEqual(this.fixture1.blurb)
|
|
|
|
delete this.fixture1.blurb
|
2014-03-13 21:50:52 -04:00
|
|
|
expect(util.i18n(this.fixture1, 'blurb', 'en')).toEqual(null)
|
2014-03-12 19:11:01 -04:00
|
|
|
|
|
|
|
it 'i18n can fall forward if a general language is not found', ->
|
2014-03-12 19:47:08 -04:00
|
|
|
expect(util.i18n(this.fixture1, 'text', 'pt')).toEqual(this.fixture1.i18n['pt-BR'].text)
|