Files
cloudron-box/src/test/translations-test.js

69 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-11-19 23:38:59 +01:00
/* jslint node:true */
/* global it:false */
/* global describe:false */
'use strict';
2021-06-03 12:20:44 -07:00
const expect = require('expect.js'),
translations = require('../translations.js');
2020-11-19 23:38:59 +01:00
describe('translation', function () {
describe('translate', function () {
it('nonexisting token', function () {
2024-07-05 12:41:51 +02:00
const assets = { translations: {}, fallback: {} };
const out = translations.translate('Foo {{ bar }}', assets);
2020-11-19 23:38:59 +01:00
expect(out).to.contain('{{ bar }}');
});
it('existing token', function () {
2024-07-05 12:41:51 +02:00
const assets = { translations: { bar: 'here' }, fallback: {} };
const out = translations.translate('Foo {{ bar }}', assets);
2020-11-19 23:38:59 +01:00
expect(out).to.contain('here');
});
it('existing token as fallback', function () {
2024-07-05 12:41:51 +02:00
const assets = { translations: {}, fallback: { bar: 'here' } };
const out = translations.translate('Foo {{ bar }}', assets);
2020-11-19 23:38:59 +01:00
expect(out).to.contain('here');
});
it('existing token deep', function () {
2024-07-05 12:41:51 +02:00
const assets = { translations: { bar: { baz: { foo: 'here' }}}, fallback: {} };
const out = translations.translate('Foo {{ bar.baz.foo }}', assets);
2020-11-19 23:38:59 +01:00
expect(out).to.contain('here');
});
it('existing token deep as fallback', function () {
2024-07-05 12:41:51 +02:00
const assets = { translations: { bar: '' }, fallback: { bar: { baz: { foo: 'here' } } } };
const out = translations.translate('Foo {{ bar.baz.foo }}', assets);
2020-11-19 23:38:59 +01:00
expect(out).to.contain('here');
});
it('with whitespace tokens', function () {
2024-07-05 12:41:51 +02:00
const assets = {
translations: {
something: {
missing: {
there: '1'
}
},
here: '2',
there: '3',
foo: '4',
bar: '5'
2020-11-19 23:38:59 +01:00
},
2024-07-05 12:41:51 +02:00
fallback: {}
2020-11-19 23:38:59 +01:00
};
2022-04-14 17:41:41 -05:00
const input = 'Hello {{ something.missing.there}} and some more {{here}} and {{ there }} with odd spacing {{foo }} lots of{{ bar }}';
2020-11-19 23:38:59 +01:00
const out = translations.translate(input, assets);
2020-11-19 23:38:59 +01:00
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');
});
});
});