You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-08-07 21:23:00 +03:00
fix fallback for pluralized strings (#7480)
* fix fallback for pluralized cases Signed-off-by: Kerry Archibald <kerrya@element.io> * add test case for no pluralizer Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
@@ -20,6 +20,13 @@ describe('languageHandler', function() {
|
||||
type TestCase = [string, string, Record<string, unknown>, Record<string, unknown>, TranslatedString];
|
||||
const testCasesEn: TestCase[] = [
|
||||
['translates a basic string', basicString, {}, undefined, 'Rooms'],
|
||||
[
|
||||
'handles plurals when count is 0',
|
||||
plurals,
|
||||
{ count: 0 },
|
||||
undefined,
|
||||
'and 0 others...',
|
||||
],
|
||||
[
|
||||
'handles plurals when count is 1',
|
||||
plurals,
|
||||
@@ -123,8 +130,19 @@ describe('languageHandler', function() {
|
||||
setMissingEntryGenerator(counterpartDefaultMissingEntryGen);
|
||||
});
|
||||
|
||||
const lvExistingPlural = 'Uploading %(filename)s and %(count)s others';
|
||||
|
||||
// lv does not have a pluralizer function
|
||||
const noPluralizerCase = [
|
||||
'handles plural strings when no pluralizer exists for language',
|
||||
lvExistingPlural,
|
||||
{ count: 1, filename: 'test.txt' },
|
||||
undefined,
|
||||
'Uploading test.txt and 1 other',
|
||||
] as TestCase;
|
||||
|
||||
describe('_t', () => {
|
||||
it.each(testCasesEn)(
|
||||
it.each([...testCasesEn, noPluralizerCase])(
|
||||
"%s and translates with fallback locale",
|
||||
async (_d, translationString, variables, tags, result) => {
|
||||
expect(_t(translationString, variables, tags)).toEqual(result);
|
||||
@@ -133,7 +151,7 @@ describe('languageHandler', function() {
|
||||
});
|
||||
|
||||
describe('_tDom()', () => {
|
||||
it.each(testCasesEn)(
|
||||
it.each([...testCasesEn, noPluralizerCase])(
|
||||
"%s and translates with fallback locale, attributes fallback locale",
|
||||
async (_d, translationString, variables, tags, result) => {
|
||||
expect(_tDom(translationString, variables, tags)).toEqual(<span lang="en">{ result }</span>);
|
||||
|
Reference in New Issue
Block a user