Skip to content

Commit

Permalink
update getLocalizedCountries to return a sorted array (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fbasham authored Feb 26, 2025
1 parent 3b9a051 commit 5d668ea
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion frontend/app/.server/services/locale-data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ type LocalizedCountry = Readonly<{
}>;

export function getLocalizedCountries(locale: Language = 'en'): readonly LocalizedCountry[] {
return getCountries().map((country) => ({
const { PP_CANADA_COUNTRY_CODE } = serverEnvironment;
const countries = getCountries().map((country) => ({
id: country.id,
name: country[locale === 'en' ? 'nameEn' : 'nameFr'],
}));
return countries
.filter((country) => country.id === PP_CANADA_COUNTRY_CODE)
.concat(
countries
.filter((country) => country.id !== PP_CANADA_COUNTRY_CODE)
.sort((a, b) => a.name.localeCompare(b.name, locale, { sensitivity: 'base' })),
);
}

type ProvinceTerritory = Readonly<{
Expand Down

0 comments on commit 5d668ea

Please sign in to comment.