Skip to content

Commit

Permalink
feat(common): Properly replace umlauts and Eszett for German lang (#2616
Browse files Browse the repository at this point in the history
)
  • Loading branch information
floze authored Feb 26, 2024
1 parent cc85202 commit 84ba64f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions packages/common/src/normalize-string.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@ describe('normalizeString()', () => {
expect(normalizeString('Capture d’écran')).toBe('capture decran');
expect(normalizeString('Capture d‘écran')).toBe('capture decran');
});

it('replaces eszett with double-s digraph', () => {
expect(normalizeString('KONGREẞ im Straßennamen')).toBe('kongress im strassennamen');
});

// works for German language, might not work for e.g. Finnish language
it('replaces combining diaeresis with e', () => {
expect(normalizeString('Ja quäkt Schwyz Pöbel vor Gmünd')).toBe('ja quaekt schwyz poebel vor gmuend');
});
});
3 changes: 3 additions & 0 deletions packages/common/src/normalize-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
export function normalizeString(input: string, spaceReplacer = ' '): string {
return (input || '')
.normalize('NFD')
.replace(/[\u00df]/g, 'ss')
.replace(/[\u1e9e]/g, 'SS')
.replace(/[\u0308]/g, 'e')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
.replace(/[!"£$%^&*()+[\]{};:@#~?\\/,|><`¬'=‘’©®™]/g, '')
Expand Down
6 changes: 3 additions & 3 deletions packages/core/e2e/collection.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ describe('Collection resolver', () => {
'accessories',
);
expect(createCollection.translations.find(t => t.languageCode === LanguageCode.de)?.slug).toBe(
'zubehor',
'zubehoer',
);
});

Expand Down Expand Up @@ -285,7 +285,7 @@ describe('Collection resolver', () => {
'accessories-2',
);
expect(createCollection.translations.find(t => t.languageCode === LanguageCode.de)?.slug).toBe(
'zubehor-2',
'zubehoer-2',
);
});

Expand Down Expand Up @@ -317,7 +317,7 @@ describe('Collection resolver', () => {
'accessories',
);
expect(createCollection.translations.find(t => t.languageCode === LanguageCode.de)?.slug).toBe(
'zubehor',
'zubehoer',
);
});

Expand Down

0 comments on commit 84ba64f

Please sign in to comment.