feat: add a new library in setting general

This commit is contained in:
Thales Euflauzino 2024-08-27 14:41:24 -03:00
parent 15c21164e4
commit f4cf33d369

View file

@ -1,5 +1,6 @@
import { useContext, useEffect, useState } from "react"; import { useContext, useEffect, useState } from "react";
import ISO6391 from "iso-639-1"; import languages from "@cospired/i18n-iso-languages";
import languagesEn from "@cospired/i18n-iso-languages/langs/en.json";
import { import {
TextField, TextField,
@ -21,6 +22,14 @@ interface LanguageOption {
nativeName: string; nativeName: string;
} }
languages.registerLocale(languagesEn);
const customLanguageNames = {
ptBR: "Português (Brasil)",
ptPT: "Português (Portugal)",
// Adicione outros idiomas personalizados aqui, se necessário
};
export function SettingsGeneral() { export function SettingsGeneral() {
const { t } = useTranslation("settings"); const { t } = useTranslation("settings");
@ -52,7 +61,9 @@ export function SettingsGeneral() {
orderBy( orderBy(
Object.keys(languageResources).map((language) => { Object.keys(languageResources).map((language) => {
return { return {
nativeName: ISO6391.getNativeName(language), nativeName:
customLanguageNames[language] ||
languages.getName(language, "en"),
option: language, option: language,
}; };
}), }),
@ -93,7 +104,7 @@ export function SettingsGeneral() {
function updateFormWithUserPreferences() { function updateFormWithUserPreferences() {
if (userPreferences) { if (userPreferences) {
const parsedLanguage = userPreferences.language.split("-")[0]; const parsedLanguage = userPreferences.language;
setForm((prev) => ({ setForm((prev) => ({
...prev, ...prev,