diff --git a/js/components/search-box.js b/js/components/search-box.js
index 447df2e..2f67b0b 100644
--- a/js/components/search-box.js
+++ b/js/components/search-box.js
@@ -3,21 +3,23 @@ import { escapeHTML } from '../utils/helpers.js'
import { categoriesService } from '../services/categories.js'
const COUNTRIES = [
- // German-speaking
'ch', 'de', 'at', 'li', 'lu',
- // French-speaking
'fr', 'be',
- // English-speaking
'gb', 'us', 'ca', 'au', 'nz', 'ie', 'za',
- // Italian
'it',
- // Spanish-speaking
'es', 'mx', 'ar', 'co', 'cl',
- // Portuguese-speaking
'pt', 'br',
- // Russian-speaking
'ru', 'by', 'kz'
]
+
+// Sort alphabetically by translated name, but pin CH first
+function getSortedCountries() {
+ return [...COUNTRIES].sort((a, b) => {
+ if (a === 'ch') return -1
+ if (b === 'ch') return 1
+ return t(`countries.${a}`).localeCompare(t(`countries.${b}`))
+ })
+}
const RADIUS_OPTIONS = [5, 10, 20, 50, 100, 200]
class SearchBox extends HTMLElement {
@@ -321,7 +323,7 @@ class SearchBox extends HTMLElement {
- ${COUNTRIES.map(c => `
+ ${getSortedCountries().map(c => `
@@ -356,7 +358,7 @@ class SearchBox extends HTMLElement {
- ${COUNTRIES.map(c => `
+ ${getSortedCountries().map(c => `
@@ -1205,4 +1207,4 @@ style.textContent = /* css */`
`
document.head.appendChild(style)
-export { SearchBox, COUNTRIES, RADIUS_OPTIONS }
+export { SearchBox, COUNTRIES, getSortedCountries, RADIUS_OPTIONS }