Skip to content

Instantly share code, notes, and snippets.

@asonnleitner
Created July 20, 2023 18:43
Show Gist options
  • Save asonnleitner/9d2a3f87cdab2078a476bfc3ac54691c to your computer and use it in GitHub Desktop.
Save asonnleitner/9d2a3f87cdab2078a476bfc3ac54691c to your computer and use it in GitHub Desktop.
const locales = ['cs', 'hu', 'pl', 'ro', 'sk', 'en']
const countries = ['CZ', 'HU', 'PL', 'RO', 'SK', 'US']
export async function fetchTerritories(locale: string) {
const response = await fetch(`https://raw.githubusercontent.com/unicode-org/cldr-json/main/cldr-json/cldr-localenames-full/main/${locale}/territories.json`)
const json = await response.json() as Record<string, Record<string, Record<string, Record<string, Record<string, string>>>>>
return json.main[locale].localeDisplayNames.territories
}
// get translations from all locales for all territories
export async function getTerritories() {
const territories = {} as Record<string, Record<string, string>>
for (const locale of locales) {
const localeTerritories = await fetchTerritories(locale)
for (const territory in localeTerritories) {
territories[territory] = {
...territories[territory],
[locale]: localeTerritories[territory],
}
}
}
return territories
}
(async () => {
const territories = await getTerritories()
const countriesTerritories = {} as Record<string, Record<string, string>>
for (const locale of locales) {
for (const country of countries) {
countriesTerritories[locale] = {
...countriesTerritories[locale],
[country]: territories[country][locale],
}
}
}
console.log(JSON.stringify(countriesTerritories, null, 2))
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment