-
Notifications
You must be signed in to change notification settings - Fork 29.9k
/
lingui__core-tests.ts
98 lines (87 loc) · 2.55 KB
/
lingui__core-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import {
i18n,
setupI18n,
Catalog,
Catalogs,
MessageOptions,
LanguageData,
I18n,
date,
number,
i18nMark
} from '@lingui/core';
const age = 12;
const templateResult: string = i18n.t`${age} years old`;
const templateIdResult: string = i18n.t('templateId')`${age} years old`;
const translateResult: string = i18n._('age', { age }, { defaults: '{age} years old' });
const count = 42;
const pluralResult: string = i18n.plural({
value: count,
0: 'no books',
one: '# book',
other: '# books'
});
const pluralIdResult: string = i18n.plural('pluralId', {
value: count,
0: 'no books',
one: '# book',
other: '# books'
});
const selectOrdinalResult: string = i18n.selectOrdinal({
value: count,
0: 'Zeroth book',
one: '#st book',
two: '#nd book',
few: '#rd book',
other: '#th book'
});
const selectOrdinalIdResult: string = i18n.selectOrdinal('selectOrdinalId', {
value: count,
0: 'Zeroth book',
one: '#st book',
two: '#nd book',
few: '#rd book',
other: '#th book'
});
const gender = 'female';
const numOfGuests = 2;
const host = 'Amy';
const guest = 'Bob';
const selectResult = i18n.select({
value: gender,
female: i18n.plural({
value: numOfGuests,
offset: 1,
0: i18n.t`${host} does not give a party.`,
1: i18n.t`${host} invites ${guest} to her party.`,
2: i18n.t`${host} invites ${guest} and one other person to her party.`,
other: i18n.t`${host} invites ${guest} and # other people to her party.`
}),
male: 'male',
other: 'other'
});
const selectIdResult = i18n.select('selectId', {
value: gender,
female: 'female',
male: 'male',
other: 'other'
});
const catalog: Catalog = {
messages: {
age(a) {
return [a('age'), 'años de edad'];
}
}
};
function missingFn(language: string, id: string) {
return id;
}
const catalogs: Catalogs = { es: catalog };
const setupResult: I18n = setupI18n({ catalogs, language: 'es' });
const setupResultLocales: I18n = setupI18n({ locales: ['en-UK', 'ar-AS'] });
const setupResultMissingText: I18n = setupI18n({ missing: 'missing' });
const setupResultMissingFn: I18n = setupI18n({ missing: missingFn });
const setupResultCombined: I18n = setupI18n({ catalogs, language: 'de', locales: ['en-UK', 'ar-AS'], missing: missingFn });
const formattedDate: string = date('en', { timeZone: 'UTC' })(new Date());
const formattedNumber: string = number('en', { style: 'currency', currency: 'EUR' })(1234.56);
const mark: string = i18nMark('mark');