Skip to content

Commit

Permalink
Merge pull request #1851 from getAlby/refactor/i18n-config
Browse files Browse the repository at this point in the history
Refactor/i18n config
  • Loading branch information
bumi authored Dec 11, 2022
2 parents cf0aca3 + 6a04000 commit 76e4cee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app/context/SettingsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const SettingsProvider = ({

// need to switch i.e. `pt_BR` to `pt-br`
const daysjsLocaleFormatted = settings.locale
.toLocaleLowerCase()
.toLowerCase()
.replace("_", "-");
dayjs.locale(daysjsLocaleFormatted);
}, [settings.locale]);
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/currencyConvert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getFormattedFiat = (params: {
}) => {
const fiatValue = Number(params.amount) * params.rate;

const l = (params.locale || "en").toLocaleLowerCase().replace("_", "-");
const l = (params.locale || "en").toLowerCase().replace("_", "-");
return new Intl.NumberFormat(l || "en", {
style: "currency",
currency: params.currency,
Expand All @@ -24,7 +24,7 @@ export const getFormattedNumber = (params: {
amount: number | string;
locale: string;
}) => {
const l = (params.locale || "en").toLocaleLowerCase().replace("_", "-");
const l = (params.locale || "en").toLowerCase().replace("_", "-");
return new Intl.NumberFormat(l || "en").format(Number(params.amount));
};

Expand Down
16 changes: 9 additions & 7 deletions src/i18n/i18nConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// dayjs locales must be imported as well
// dayjs locales must be imported as well, list: https://github.com/iamkun/dayjs/tree/dev/src/locale
import "dayjs/locale/es";
import "dayjs/locale/it";
import "dayjs/locale/pt-br";
import "dayjs/locale/sv";
import i18n from "i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import { initReactI18next } from "react-i18next";
Expand All @@ -24,6 +26,11 @@ export const resources = {
common: es.common,
components: es.components,
},
it: {
translation: it.translation,
common: it.common,
components: it.components,
},
"pt-BR": {
translation: pt_BR.translation,
common: pt_BR.common,
Expand All @@ -34,20 +41,15 @@ export const resources = {
common: sv.common,
components: sv.components,
},
it: {
translation: it.translation,
common: it.common,
components: it.components,
},
} as const;

// needs to be aligned with `resources`
export const supportedLocales = [
{ locale: "en", label: "English" },
{ locale: "es", label: "Español" },
{ locale: "it", label: "Italiano" },
{ locale: "pt-BR", label: "Português (Brasil)" },
{ locale: "sv", label: "Svenska" },
{ locale: "it", label: "Italiano" },
];

i18n
Expand Down

0 comments on commit 76e4cee

Please sign in to comment.