1 import {Translator} from "../translations";
4 describe('Translations Service', () => {
6 let $trans: Translator;
9 $trans = new Translator();
12 describe('choice()', () => {
14 test('it pluralises as expected', () => {
18 translation: `cat`, count: 10000,
22 translation: `cat|cats`, count: 1,
26 translation: `cat|cats`, count: 0,
30 translation: `cat|cats`, count: 2,
34 translation: `{0} cat|[1,100] dog|[100,*] turtle`, count: 0,
38 translation: `{0} cat|[1,100] dog|[100,*] turtle`, count: 40,
42 translation: `{0} cat|[1,100] dog|[100,*] turtle`, count: 101,
47 for (const testCase of cases) {
48 const output = $trans.choice(testCase.translation, testCase.count, {});
49 expect(output).toEqual(testCase.expected);
53 test('it replaces as expected', () => {
54 const caseA = $trans.choice(`{0} cat|[1,100] :count dog|[100,*] turtle`, 4, {count: '5'});
55 expect(caseA).toEqual('5 dog');
57 const caseB = $trans.choice(`an :a :b :c dinosaur|many`, 1, {a: 'orange', b: 'angry', c: 'big'});
58 expect(caseB).toEqual('an orange angry big dinosaur');
61 test('it provides count as a replacement by default', () => {
62 const caseA = $trans.choice(`:count cats|:count dogs`, 4);
63 expect(caseA).toEqual('4 dogs');
66 test('not provided replacements are left as-is', () => {
67 const caseA = $trans.choice(`An :a dog`, 5, {});
68 expect(caseA).toEqual('An :a dog');