Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow searching for country names with diacritics #3443

Merged
merged 1 commit into from
May 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions assets/localization-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,15 @@ if (!customElements.get('localization-form')) {
}
}

normalizeString(str) {
return str
.normalize('NFD')
.replace(/\p{Diacritic}/gu, '')
Copy link
Contributor Author

@hamideha hamideha Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\p Unicode character class escape is supported in all major browsers since 2020. Should I also be targeting older browsers or is this fine?

Copy link
Contributor Author

@hamideha hamideha Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the docs it mentions just the last 2 releases but just want to make sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last 2 releases is correct. We only support evergreen browsers, so we don't need to worry about anything that old.

.toLowerCase();
}

filterCountries() {
const searchValue = this.elements.search.value.toLowerCase();
const searchValue = this.normalizeString(this.elements.search.value);
const popularCountries = this.querySelector('.popular-countries');
const allCountries = this.querySelectorAll('a');
let visibleCountries = allCountries.length;
Expand All @@ -151,7 +158,7 @@ if (!customElements.get('localization-form')) {
}

allCountries.forEach((item) => {
const countryName = item.querySelector('.country').textContent.toLowerCase();
const countryName = this.normalizeString(item.querySelector('.country').textContent);
if (countryName.indexOf(searchValue) > -1) {
item.parentElement.classList.remove('hidden');
visibleCountries++;
Expand Down
Loading