Skip to content

Commit

Permalink
fix: support hyphens in translation case variables (#1539)
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrueber committed Mar 8, 2024
1 parent f11ec1c commit 9487fc3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/app/core/utils/translate/pwa-translate-compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,16 @@ describe('Pwa Translate Compiler', () => {

describe('with translate functionality and variable', () => {
beforeEach(() => {
translate.set('key.type', '{{ type, select, =a{A} =b{B} other{something else} }}');
translate.set('key.type', '{{ type, select, =a{A} =b{B} =a-b{A&B} other{something else} }}');
translate.set('message', 'You chose {{ type, translate, key.type }}.');
});

it.each`
type | expected
${'a'} | ${'You chose A.'}
${'b'} | ${'You chose B.'}
${'c'} | ${'You chose something else.'}
type | expected
${'a'} | ${'You chose A.'}
${'b'} | ${'You chose B.'}
${'a-b'} | ${'You chose A&B.'}
${'c'} | ${'You chose something else.'}
`('should translate when $type was given as argument', ({ type, expected }) => {
expect(translate.instant('message', { type })).toEqual(expected);
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/utils/translate/pwa-translate-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class PWATranslateCompiler implements TranslateCompiler {
* - "\s*" captures (and ignores) additional whitespace
* - global matching ("/g") must be active to iterate over matches
*/
private static CASE_REGEX = /(zero|one|two|few|many|other|=\w+)\s*\{(.*?)\}/g;
private static CASE_REGEX = /(zero|one|two|few|many|other|=[\w-]+)\s*\{(.*?)\}/g;

/**
* regular expression for matching simple variables that
Expand Down

0 comments on commit 9487fc3

Please sign in to comment.