translation.js -> translations.js

kept confusing my why i can't find this file! this is in line
with the rest of our code
This commit is contained in:
Girish Ramakrishnan
2024-07-05 12:45:23 +02:00
parent bf51a60986
commit bcf497b460
8 changed files with 27 additions and 27 deletions

View File

@@ -0,0 +1,68 @@
/* jslint node:true */
/* global it:false */
/* global describe:false */
'use strict';
const expect = require('expect.js'),
translations = require('../translations.js');
describe('translation', function () {
describe('translate', function () {
it('nonexisting token', function () {
const assets = { translations: {}, fallback: {} };
const out = translations.translate('Foo {{ bar }}', assets);
expect(out).to.contain('{{ bar }}');
});
it('existing token', function () {
const assets = { translations: { bar: 'here' }, fallback: {} };
const out = translations.translate('Foo {{ bar }}', assets);
expect(out).to.contain('here');
});
it('existing token as fallback', function () {
const assets = { translations: {}, fallback: { bar: 'here' } };
const out = translations.translate('Foo {{ bar }}', assets);
expect(out).to.contain('here');
});
it('existing token deep', function () {
const assets = { translations: { bar: { baz: { foo: 'here' }}}, fallback: {} };
const out = translations.translate('Foo {{ bar.baz.foo }}', assets);
expect(out).to.contain('here');
});
it('existing token deep as fallback', function () {
const assets = { translations: { bar: '' }, fallback: { bar: { baz: { foo: 'here' } } } };
const out = translations.translate('Foo {{ bar.baz.foo }}', assets);
expect(out).to.contain('here');
});
it('with whitespace tokens', function () {
const assets = {
translations: {
something: {
missing: {
there: '1'
}
},
here: '2',
there: '3',
foo: '4',
bar: '5'
},
fallback: {}
};
const input = 'Hello {{ something.missing.there}} and some more {{here}} and {{ there }} with odd spacing {{foo }} lots of{{ bar }}';
const out = translations.translate(input, assets);
expect(out).to.contain('1');
expect(out).to.contain('2');
expect(out).to.contain('3');
expect(out).to.contain('4');
expect(out).to.contain('5');
});
});
});