From 9ff76e41985d5b751e168887a6dba5b2c0ae9818 Mon Sep 17 00:00:00 2001 From: tjs Date: Mon, 17 Apr 2023 14:03:35 -0400 Subject: [PATCH] add language selector to settings --- components/settings/DisplaySettings.tsx | 57 +++++++++++++------------ 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/components/settings/DisplaySettings.tsx b/components/settings/DisplaySettings.tsx index 2c1b6faf..9ea5c32c 100644 --- a/components/settings/DisplaySettings.tsx +++ b/components/settings/DisplaySettings.tsx @@ -5,12 +5,12 @@ import ChartMiddleOBRight from '@components/icons/ChartMiddleOBRight' import ChartOnLeft from '@components/icons/ChartOnLeft' import ChartOnRight from '@components/icons/ChartOnRight' import Tooltip from '@components/shared/Tooltip' -// import dayjs from 'dayjs' +import dayjs from 'dayjs' import useLocalStorageState from 'hooks/useLocalStorageState' import { useTranslation } from 'next-i18next' import { useTheme } from 'next-themes' -// import { useRouter } from 'next/router' -// import { useCallback } from 'react' +import { useCallback } from 'react' +import { useRouter } from 'next/router' import { NOTIFICATION_POSITION_KEY, SIZE_INPUT_UI_KEY, @@ -28,17 +28,17 @@ const NOTIFICATION_POSITIONS = [ const TRADING_CHARTS = ['custom', 'trading-view'] const TRADE_FORM_UI = ['slider', 'buttons'] -// const LANGS = [ -// { locale: 'en', name: 'english', description: 'english' }, -// { locale: 'ru', name: 'russian', description: 'russian' }, -// { locale: 'es', name: 'spanish', description: 'spanish' }, -// { -// locale: 'zh_tw', -// name: 'chinese-traditional', -// description: 'traditional chinese', -// }, -// { locale: 'zh', name: 'chinese', description: 'simplified chinese' }, -// ] +const LANGS = [ + { locale: 'en', name: 'english', description: 'english' }, + // { locale: 'ru', name: 'russian', description: 'russian' }, + // { locale: 'es', name: 'spanish', description: 'spanish' }, + { + locale: 'zh_tw', + name: 'chinese-traditional', + description: 'traditional chinese', + }, + // { locale: 'zh', name: 'chinese', description: 'simplified chinese' }, +] export const THEMES = [ 'light', @@ -56,9 +56,12 @@ export const THEMES = [ const DisplaySettings = () => { const { t } = useTranslation(['common', 'settings']) const { theme, setTheme } = useTheme() - // const [savedLanguage, setSavedLanguage] = useLocalStorageState('language', '') - // const router = useRouter() - // const { pathname, asPath, query } = router + const [savedLanguage, setSavedLanguage] = useLocalStorageState( + 'language', + 'en' + ) + const router = useRouter() + const { pathname, asPath, query } = router const [notificationPosition, setNotificationPosition] = useLocalStorageState( NOTIFICATION_POSITION_KEY, 'bottom-left' @@ -76,14 +79,14 @@ const DisplaySettings = () => { 'chartLeft' ) - // const handleLangChange = useCallback( - // (l: string) => { - // setSavedLanguage(l) - // router.push({ pathname, query }, asPath, { locale: l }) - // dayjs.locale(l == 'zh_tw' ? 'zh-tw' : l) - // }, - // [router] - // ) + const handleLangChange = useCallback( + (l: string) => { + setSavedLanguage(l) + router.push({ pathname, query }, asPath, { locale: l }) + dayjs.locale(l == 'zh_tw' ? 'zh-tw' : l) + }, + [router, pathname, query, asPath, setSavedLanguage] + ) return ( <> @@ -106,7 +109,7 @@ const DisplaySettings = () => { - {/*
+

{t('settings:language')}

{ names={LANGS.map((val) => t(`settings:${val.name}`))} />
-
*/} +

{t('settings:notification-position')}