From 110cc0c769f45f3a0439acc32131ef69ea8e0542 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 4 Mar 2022 19:51:43 -0800 Subject: [PATCH] Localize filter bar and dropdowns --- components/ElementToggle/index.scss | 5 +++++ components/ElementToggle/index.tsx | 35 +++++++++++++++++------------ components/FilterBar/index.tsx | 33 ++++++++++++++------------- components/GridRep/index.tsx | 24 ++++++++++++-------- components/RaidDropdown/index.tsx | 10 +++++++-- public/locales/en/common.json | 33 ++++++++++++++++++++++++++- public/locales/ja/common.json | 33 ++++++++++++++++++++++++++- 7 files changed, 131 insertions(+), 42 deletions(-) diff --git a/components/ElementToggle/index.scss b/components/ElementToggle/index.scss index c97a1d19..06d7a160 100644 --- a/components/ElementToggle/index.scss +++ b/components/ElementToggle/index.scss @@ -17,6 +17,11 @@ font-size: $font-regular; padding: ($unit) $unit * 2; + &.ja { + padding-top: 6px; + padding-bottom: 10px; + } + &:hover { cursor: pointer; } diff --git a/components/ElementToggle/index.tsx b/components/ElementToggle/index.tsx index 68486bdb..fe6a9e99 100644 --- a/components/ElementToggle/index.tsx +++ b/components/ElementToggle/index.tsx @@ -1,4 +1,7 @@ import React from 'react' +import { useRouter } from 'next/router' +import { useTranslation } from 'next-i18next' + import * as ToggleGroup from '@radix-ui/react-toggle-group' import './index.scss' @@ -9,28 +12,32 @@ interface Props { } const ElementToggle = (props: Props) => { + const router = useRouter() + const { t } = useTranslation('common') + const locale = (router.locale && ['en', 'ja'].includes(router.locale)) ? router.locale : 'en' + return ( - - Null + + {t('elements.null')} - - Wind + + {t('elements.wind')} - - Fire + + {t('elements.fire')} - - Water + + {t('elements.water')} - - Earth + + {t('elements.earth')} - - Dark + + {t('elements.dark')} - - Light + + {t('elements.light')} ) diff --git a/components/FilterBar/index.tsx b/components/FilterBar/index.tsx index c7b3c3c2..b34873ee 100644 --- a/components/FilterBar/index.tsx +++ b/components/FilterBar/index.tsx @@ -1,4 +1,5 @@ import React from 'react' +import { useTranslation } from 'next-i18next' import classNames from 'classnames' import RaidDropdown from '~components/RaidDropdown' @@ -12,6 +13,8 @@ interface Props { } const FilterBar = (props: Props) => { + const { t } = useTranslation('common') + const elementSelect = React.createRef() const raidSelect = React.createRef() const recencySelect = React.createRef() @@ -33,14 +36,14 @@ const FilterBar = (props: Props) => {
{props.children} { ref={raidSelect} />
) diff --git a/components/GridRep/index.tsx b/components/GridRep/index.tsx index 86fef4b7..ba265a6a 100644 --- a/components/GridRep/index.tsx +++ b/components/GridRep/index.tsx @@ -1,6 +1,8 @@ import React, { useEffect, useState } from 'react' +import { useRouter } from 'next/router' import { useSnapshot } from 'valtio' +import { useTranslation } from 'next-i18next' import classNames from 'classnames' import { accountState } from '~utils/accountState' @@ -30,6 +32,10 @@ const GridRep = (props: Props) => { const { account } = useSnapshot(accountState) + const router = useRouter() + const { t } = useTranslation('common') + const locale = (router.locale && ['en', 'ja'].includes(router.locale)) ? router.locale : 'en' + const [mainhand, setMainhand] = useState() const [weapons, setWeapons] = useState>({}) @@ -66,12 +72,12 @@ const GridRep = (props: Props) => { function generateMainhandImage() { return (mainhand) ? - {mainhand?.name.en} : '' + {mainhand?.name[locale]} : '' } function generateGridImage(position: number) { return (weapons[position]) ? - {weapons[position]?.name.en} : '' + {weapons[position]?.name[locale]} : '' } function sendSaveData() { @@ -96,10 +102,10 @@ const GridRep = (props: Props) => { const details = (
-

{ (props.name) ? props.name : 'Untitled' }

+

{ (props.name) ? props.name : t('no_title') }

-
{ (props.raid) ? props.raid.name.en : 'No raid set' }
- +
{ (props.raid) ? props.raid.name[locale] : t('no_raid') }
+
) @@ -108,8 +114,8 @@ const GridRep = (props: Props) => {
-

{ (props.name) ? props.name : 'Untitled' }

-
{ (props.raid) ? props.raid.name.en : 'No raid set' }
+

{ (props.name) ? props.name : t('no_title') }

+
{ (props.raid) ? props.raid.name[locale] : t('no_raid') }
{ (!props.user || (account.user && account.user.id !== props.user.id)) ?
) diff --git a/components/RaidDropdown/index.tsx b/components/RaidDropdown/index.tsx index 47ad6b26..72a27330 100644 --- a/components/RaidDropdown/index.tsx +++ b/components/RaidDropdown/index.tsx @@ -1,4 +1,6 @@ import React, { useCallback, useEffect, useState } from 'react' +import { useRouter } from 'next/router' +import { useTranslation } from 'next-i18next' import { appState } from '~utils/appState' import api from '~utils/api' @@ -14,6 +16,10 @@ interface Props { } const RaidDropdown = React.forwardRef(function useFieldSet(props, ref) { + const router = useRouter() + const { t } = useTranslation('common') + const locale = (router.locale && ['en', 'ja'].includes(router.locale)) ? router.locale : 'en' + const [raids, setRaids] = useState() const raidGroups = [ @@ -37,7 +43,7 @@ const RaidDropdown = React.forwardRef(function useFiel id: '0', name: { en: 'All raids', - jp: '全て' + ja: '全てのマルチ' }, level: 0, group: 0, @@ -65,7 +71,7 @@ const RaidDropdown = React.forwardRef(function useFiel const options = raids && raids.length > 0 && raids[index].length > 0 && raids[index].sort((a, b) => a.element - b.element).map((item, i) => { return ( - + ) }) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 6609bfe2..dd3ce87c 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -8,6 +8,34 @@ "new": "New", "wiki": "View more on gbf.wiki" }, + "elements": { + "null": "Null", + "wind": "Wind", + "fire": "Fire", + "water": "Water", + "earth": "Earth", + "dark": "Dark", + "light": "Light", + "full": { + "all": "All elements", + "null": "Null", + "wind": "Wind", + "fire": "Fire", + "water": "Water", + "earth": "Earth", + "dark": "Dark", + "light": "Light" + } + }, + "recency": { + "all_time": "All time", + "last_day": "Last day", + "last_week": "Last week", + "last_month": "Last month", + "last_3_months": "Last 3 months", + "last_6_months": "Last 6 months", + "last_year": "Last year" + }, "summons": { "main": "Main Summon", "friend": "Friend Summon", @@ -66,5 +94,8 @@ "loading": "Loading teams...", "not_found": "No teams found" }, - "coming_soon": "Coming Soon" + "coming_soon": "Coming Soon", + "no_title": "Untitled", + "no_raid": "No raid", + "no_user": "Anonymous" } diff --git a/public/locales/ja/common.json b/public/locales/ja/common.json index 9ba8d7a3..ee0afd09 100644 --- a/public/locales/ja/common.json +++ b/public/locales/ja/common.json @@ -8,6 +8,34 @@ "new": "作成", "wiki": "gbf.wikiで詳しく見る" }, + "elements": { + "null": "無", + "wind": "風", + "fire": "火", + "water": "水", + "earth": "土", + "dark": "闇", + "light": "光", + "full": { + "all": "全属性", + "null": "無属性", + "wind": "風属性", + "fire": "火属性", + "water": "水属性", + "earth": "土属性", + "dark": "闇属性", + "light": "光属性" + } + }, + "recency": { + "all_time": "全ての期間", + "last_day": "1日", + "last_week": "7日", + "last_month": "1ヶ月", + "last_3_months": "3ヶ月", + "last_6_months": "6ヶ月", + "last_year": "1年" + }, "summons": { "main": "メイン", "friend": "フレンド", @@ -66,6 +94,9 @@ "loading": "ロード中...", "not_found": "編成は見つかりませんでした" }, - "coming_soon": "開発中" + "coming_soon": "開発中", + "no_title": "無題", + "no_raid": "マルチなし", + "no_user": "無名" } \ No newline at end of file