// Hooks import { useState } from 'react' import { useTranslation } from 'next-i18next' import { useBackend } from 'site/hooks/useBackend.mjs' import { useToast } from 'site/hooks/useToast.mjs' // Components import { BackToAccountButton, updateAccount, Choice } from './shared.mjs' import { SaveSettingsButton } from 'site/components/buttons/save-settings-button.mjs' // Config import { freeSewingConfig as conf } from 'site/freesewing.config.mjs' export const ns = ['account', 'locales', 'toast'] export const LanguageSettings = ({ app, title = false }) => { const backend = useBackend(app) const toast = useToast() const { t } = useTranslation(ns) const [language, setLanguage] = useState(app.account.language || 'en') const update = async (lang) => { if (lang !== language) { app.startLoading() setLanguage(lang) const result = await backend.updateAccount({ language: lang }) if (result === true) toast.for.settingsSaved() else toast.for.backendError() app.stopLoading() } } return ( <> {title ?

{t('languageTitle')}

: null} {conf.languages.map((val) => ( {t(`locales:${val}`)} ))} ) }