Skip to content

Commit

Permalink
DownloadCard: use variant of language if exists first
Browse files Browse the repository at this point in the history
  • Loading branch information
starsep committed Nov 14, 2023
1 parent bc9f650 commit 7eba7a3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/components/downloadCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ const worldCountryCode = "WORLD";

export default function DownloadCard() {
const { t, i18n: { resolvedLanguage: language } } = useTranslation();
function resolvedLanguageToBackendLanguage(): string {
let result = language;
if (result.includes("-")) [result] = result.split("-");
result = result.toUpperCase();
return result;
}
function countryName(country: Country) {
if (country.code === worldCountryCode) return t("sidebar.world");
const backendLanguage = resolvedLanguageToBackendLanguage();
if (Object.hasOwn(country.names, backendLanguage)) {
return country.names[backendLanguage];
const backendLanguageUppercase = language.toUpperCase();
if (Object.hasOwn(country.names, backendLanguageUppercase)) {
return country.names[backendLanguageUppercase];
}
if (backendLanguageUppercase.includes("-")) {
const basicLanguage = backendLanguageUppercase.split("-")[0];
if (Object.hasOwn(country.names, basicLanguage)) {
return country.names[basicLanguage];
}
}
return country.names.default;
}
Expand Down

0 comments on commit 7eba7a3

Please sign in to comment.