Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Support Brazilian Portuguese
Browse files Browse the repository at this point in the history
  • Loading branch information
mnvr committed Feb 24, 2024
1 parent 9d8ec5c commit 1436daf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const localeName = (locale: SupportedLocale) => {
return 'Nederlands';
case 'es-ES':
return 'Español';
case 'pt-BR':
return 'Brazilian Portuguese';
}
};

Expand Down
20 changes: 12 additions & 8 deletions packages/ui/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { isDevBuild } from "@/utils/env";
import { getUserLocales } from "get-user-locale";
import { includes } from "@/utils/type-guards";
import {
type LSKey,
getLSString,
setLSString,
removeLSString,
Expand All @@ -31,6 +30,7 @@ export const supportedLocales = [
"zh-CN" /* Simplified Chinese */,
"nl-NL" /* Dutch */,
"es-ES" /* Spanish */,
"pt-BR" /* Portuguese, Brazilian */,
] as const;

/** The type of {@link supportedLocales}. */
Expand Down Expand Up @@ -193,21 +193,25 @@ const closestSupportedLocale = (
const ss = savedLocaleString;
if (ss && includes(supportedLocales, ss)) return ss;

for (const us of getUserLocales()) {
for (const ls of getUserLocales()) {
// Exact match
if (us && includes(supportedLocales, us)) return us;
if (ls && includes(supportedLocales, ls)) return ls;

// Language match
if (us.startsWith("en")) {
if (ls.startsWith("en")) {
return "en-US";
} else if (us.startsWith("fr")) {
} else if (ls.startsWith("fr")) {
return "fr-FR";
} else if (us.startsWith("zh")) {
} else if (ls.startsWith("zh")) {
return "zh-CN";
} else if (us.startsWith("nl")) {
} else if (ls.startsWith("nl")) {
return "nl-NL";
} else if (us.startsWith("es")) {
} else if (ls.startsWith("es")) {
return "es-ES";
} else if (ls.startsWith("pt-BR")) {
// We'll never get here (it'd already be an exact match), just kept
// to keep this list consistent.
return "pt-BR";
}
}

Expand Down

0 comments on commit 1436daf

Please sign in to comment.