fix: preserve German umlauts for proper transliteration - #54
Conversation
|
This looks like it was LLM-generated and overly verbose. Could the fix be as simple as not removing the combining diaeresis? - const deburredText = text.normalize('NFKD').replace(/[\u0300-\u036f]/g, '');
+ const deburredText = text.normalize('NFKD').replace(/[\u0300-\u0307\u0309-\u036f]/g, ''); |
Exclude U+0308 (combining diaeresis) from removal so speakingurl can properly map ä→ae, ö→oe, ü→ue. NFC recomposition ensures the characters are in the precomposed form speakingurl expects. Fixes lovell#50
b20b6ba to
3165261
Compare
|
Thanks for the feedback @lovell! You're right - the PR was AI-generated and the original approach was overly verbose. I've updated the PR with your simpler fix. I also added const deburredText = text.normalize('NFKD').replace(/[\u0300-\u0307\u0309-\u036f]/g, '').normalize('NFC');Verified it works: Thanks again for the better approach! |
|
Thanks for the update, are you able to add a couple of basic test cases to help prevent future regression? |
Added 4 test cases to prevent regression: - Schöner Städte Übung → schoener-staedte-uebung - München → muenchen - Größe → groesse - Ärger → aerger
|
Added test cases in commit 068299b: ava('German umlaut transliteration', function (t) {
t.plan(4);
t.true(limax('Schöner Städte Übung', { lang: 'de' }) === 'schoener-staedte-uebung');
t.true(limax('München', { lang: 'de' }) === 'muenchen');
t.true(limax('Größe', { lang: 'de' }) === 'groesse');
t.true(limax('Ärger', { lang: 'de' }) === 'aerger');
});All 11 tests pass. |
|
Thanks, does this work without the |
|
Yes, it works without // Without lang option (default behavior)
t.true(limax('München') === 'muenchen');
t.true(limax('Größe') === 'groesse');
t.true(limax('Ärger') === 'aerger');
t.true(limax('Schöner Städte Übung') === 'schoener-staedte-uebung');All 11 tests pass (8 German umlaut tests total - 4 with |
|
Thank you / danke |
This was fixed in lovell/limax#54
Summary
Fixes #50 - German umlauts (ä, ö, ü, Ä, Ö, Ü, ß) are now correctly transliterated to their digraph equivalents (ä→ae, ö→oe, ü→ue, ß→ss).
Before:
München→munchenAfter:
München→muenchenProblem
The NFKD normalization step was stripping German umlauts before speakingurl could apply its proper character mappings. For example,
üwas being normalized tou(removing the combining diaeresis), so speakingurl never saw the original character and couldn't map it toue.Solution
Preserve German umlauts (and any characters specified in custom mappings) during the normalization step using placeholders, then restore them before passing to speakingurl. This allows speakingurl's comprehensive charMap to handle German characters correctly.
The normalization is still applied to other characters (like macrons) where speakingurl's handling is less ideal.
Test plan
Pōneke→poneke)Münchenwith{custom: {'ü': 'u'}}→munchen)