Skip to content

Commit 63546ac

Browse files
committed
feat: add normalized version of language autonyms for input matching
- Added normalize() function to strip accents and lowercase text - Append normalized version in the datalist label if different from the original resolves #502
1 parent 45381c2 commit 63546ac

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

web-app/frontend/src/instruments/helpers/NameRowManager.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { WikidataLanguage, NameEntry } from '../Types';
22

3+
function normalize(str: string): string {
4+
return str
5+
.normalize('NFD') // split accents
6+
.replace(/[\u0300-\u036f]/g, ''); // remove accents
7+
}
8+
39
export interface NameRowConfig {
410
isRequired: boolean;
511
}
@@ -24,13 +30,21 @@ export class NameRowManager {
2430
row.dataset.rowIndex = String(index);
2531

2632
const datalistOptions: string = this.languages
27-
.map(
28-
(language: WikidataLanguage) => `
29-
<option value="${language.wikidata_code}" class="notranslate force-ltr">
30-
${language.autonym} - ${language.en_label}
33+
.map((language) => {
34+
const normalizedAutonym = normalize(language.autonym);
35+
// Only include normalized version if it's different
36+
const displayNormalized =
37+
normalizedAutonym !== language.autonym
38+
? ` (${normalizedAutonym})`
39+
: '';
40+
41+
return `
42+
<option
43+
value="${language.wikidata_code}"
44+
label="${language.autonym}${displayNormalized}${language.en_label}">
3145
</option>
32-
`,
33-
)
46+
`;
47+
})
3448
.join('');
3549

3650
const requiredMark = config.isRequired

0 commit comments

Comments
 (0)