From ac143a81c0c6844b849516ffaeefc618a81a3a45 Mon Sep 17 00:00:00 2001 From: Sakura Knoll Date: Mon, 3 Jan 2022 15:16:51 +0900 Subject: [PATCH] Add translation for battlesuit list page --- public/locales/en-US/common.json | 10 + public/locales/ko-KR/common.json | 9 + .../atoms/BattlesuitFeatureLabel.tsx | 13 +- src/components/atoms/TypeLabel.tsx | 15 +- src/components/atoms/ValkyrieLabel.tsx | 13 +- .../organisms/Honkai3rdNavigator.tsx | 2 +- src/lib/honkai3rd/battlesuits.ts | 248 +++++++++++++++--- src/lib/i18n.ts | 22 +- .../honkai3rd/battlesuits/[battlesuitId].tsx | 4 +- src/pages/honkai3rd/battlesuits/index.tsx | 47 ++-- src/pages/honkai3rd/elfs/[elfId].tsx | 2 +- src/pages/honkai3rd/elfs/index.tsx | 2 +- src/pages/honkai3rd/index.tsx | 2 +- src/pages/honkai3rd/stigmata/[stigmataId].tsx | 2 +- src/pages/honkai3rd/stigmata/index.tsx | 2 +- src/pages/honkai3rd/versions/[versionId].tsx | 2 +- src/pages/honkai3rd/versions/index.tsx | 2 +- src/pages/honkai3rd/weapons/[weaponId].tsx | 2 +- src/pages/honkai3rd/weapons/index.tsx | 2 +- src/server/i18n.ts | 17 ++ 20 files changed, 331 insertions(+), 87 deletions(-) create mode 100644 src/server/i18n.ts diff --git a/public/locales/en-US/common.json b/public/locales/en-US/common.json index 93f1b317..c44ca9d0 100644 --- a/public/locales/en-US/common.json +++ b/public/locales/en-US/common.json @@ -1,9 +1,19 @@ { "nav": { + "honkai-3rd": "Honkai 3rd", "versions": "Versions", "battlesuits": "Battlesuits", "weapons": "Weapons", "stigmata": "Stigmata", "elfs": "ELFs" + }, + "breadcrumb": { + "honkai-3rd": "Honkai 3rd", + "battlesuits": "Battlesuits" + }, + "battlesuits-list": { + "heading": "Battlesuits", + "filter-by-features": "Filter by Features", + "filter-by-valkyries": "Filter by Valkyries" } } diff --git a/public/locales/ko-KR/common.json b/public/locales/ko-KR/common.json index 15a6a047..795b98b9 100644 --- a/public/locales/ko-KR/common.json +++ b/public/locales/ko-KR/common.json @@ -6,5 +6,14 @@ "weapons": "무기", "stigmata": "성흔", "elfs": "무장인형" + }, + "breadcrumb": { + "honkai-3rd": "붕괴 3rd", + "battlesuits": "발키리" + }, + "battlesuits-list": { + "heading": "발키리", + "filter-by-features": "특성 필터", + "filter-by-valkyries": "발키리 필터" } } diff --git a/src/components/atoms/BattlesuitFeatureLabel.tsx b/src/components/atoms/BattlesuitFeatureLabel.tsx index 956e2674..5e053400 100644 --- a/src/components/atoms/BattlesuitFeatureLabel.tsx +++ b/src/components/atoms/BattlesuitFeatureLabel.tsx @@ -1,6 +1,8 @@ /** @jsxImportSource theme-ui */ import { Flex, Text } from '@theme-ui/components' +import { useRouter } from 'next/router' import { battlesuitFeatures } from '../../lib/honkai3rd/battlesuits' +import { translate } from '../../lib/i18n' import SquareImageBox from './SquareImageBox' interface BattlesuitFeatureLabelProps { @@ -8,24 +10,29 @@ interface BattlesuitFeatureLabelProps { } const BattlesuitFeatureLabel = ({ feature }: BattlesuitFeatureLabelProps) => { + const { locale } = useRouter() const featureData = battlesuitFeatures.find( (aFeature) => aFeature.value === feature ) if (featureData == null) { return {feature} } - const { label, icon } = featureData + + const { label, icon, krLabel } = featureData + + const translatedLabel = translate(locale, { 'ko-KR': krLabel }, label) + return ( {featureData != null && ( )} - {label} + {translatedLabel} ) } diff --git a/src/components/atoms/TypeLabel.tsx b/src/components/atoms/TypeLabel.tsx index a40a5c34..c056cea5 100644 --- a/src/components/atoms/TypeLabel.tsx +++ b/src/components/atoms/TypeLabel.tsx @@ -1,5 +1,8 @@ /** @jsxImportSource theme-ui */ import { Flex, Text } from '@theme-ui/components' +import { useRouter } from 'next/router' +import { battlesuitTypes } from '../../lib/honkai3rd/battlesuits' +import { translate } from '../../lib/i18n' import { capitalize } from '../../lib/string' import SquareImageBox from './SquareImageBox' @@ -8,7 +11,17 @@ interface TypeLabelProps { } const TypeLabel = ({ type }: TypeLabelProps) => { - const label = capitalize(type) + const battlesuitType = battlesuitTypes.find((aType) => aType.value === type) + + const { locale } = useRouter() + const label = + battlesuitType != null + ? translate( + locale, + { 'ko-KR': battlesuitType.krLabel }, + battlesuitType.label + ) + : capitalize(type) return ( diff --git a/src/components/atoms/ValkyrieLabel.tsx b/src/components/atoms/ValkyrieLabel.tsx index c2b2eb44..152ecc84 100644 --- a/src/components/atoms/ValkyrieLabel.tsx +++ b/src/components/atoms/ValkyrieLabel.tsx @@ -1,6 +1,8 @@ /** @jsxImportSource theme-ui */ import { Flex, Text } from '@theme-ui/components' +import { useRouter } from 'next/router' import { valkyries } from '../../lib/honkai3rd/battlesuits' +import { translate } from '../../lib/i18n' import SquareImageBox from './SquareImageBox' interface ValkyrieLabelProps { @@ -8,9 +10,12 @@ interface ValkyrieLabelProps { } const ValkyrieLabel = ({ valkyrie }: ValkyrieLabelProps) => { - const { icon, label } = valkyries.find( + const { icon, label, krLabel } = valkyries.find( (aValkyrie) => aValkyrie.value === valkyrie - ) || { label: valkyrie } + ) || { label: valkyrie, krLabel: valkyrie } + const { locale } = useRouter() + + const translatedLabel = translate(locale, { 'ko-KR': krLabel }, label) return ( @@ -18,11 +23,11 @@ const ValkyrieLabel = ({ valkyrie }: ValkyrieLabelProps) => { )} - {label} + {translatedLabel} ) } diff --git a/src/components/organisms/Honkai3rdNavigator.tsx b/src/components/organisms/Honkai3rdNavigator.tsx index 77201304..91f95754 100644 --- a/src/components/organisms/Honkai3rdNavigator.tsx +++ b/src/components/organisms/Honkai3rdNavigator.tsx @@ -2,7 +2,7 @@ import { NavLink, Heading, Flex } from '@theme-ui/components' import NextLink from 'next/link' import { useRouter } from 'next/router' -import { useTranslation } from 'next-i18next' +import { useTranslation } from '../../lib/i18n' const Honkai3rdNavigator = () => { const router = useRouter() diff --git a/src/lib/honkai3rd/battlesuits.ts b/src/lib/honkai3rd/battlesuits.ts index 60ae3600..c260153d 100644 --- a/src/lib/honkai3rd/battlesuits.ts +++ b/src/lib/honkai3rd/battlesuits.ts @@ -25,58 +25,230 @@ export interface BattlesuitData { } export const battlesuitFeatures = [ - { icon: 'feature-icons/physical', value: 'physical', label: 'Physical' }, - { icon: 'feature-icons/fire-dmg', value: 'fire-dmg', label: 'Fire DMG' }, - { icon: 'feature-icons/ice-dmg', value: 'ice-dmg', label: 'Ice DMG' }, + { + icon: 'feature-icons/physical', + value: 'physical', + label: 'Physical', + krLabel: '물리', + }, + { + icon: 'feature-icons/fire-dmg', + value: 'fire-dmg', + label: 'Fire DMG', + krLabel: '화염 대미지', + }, + { + icon: 'feature-icons/ice-dmg', + value: 'ice-dmg', + label: 'Ice DMG', + krLabel: '빙결 대미지', + }, { icon: 'feature-icons/lightning-dmg', value: 'lightning-dmg', label: 'Lightning DMG', + krLabel: '뇌전 대미지', + }, + { + icon: 'feature-icons/freeze', + value: 'freeze', + label: 'Freeze', + krLabel: '빙결', + }, + { + icon: 'feature-icons/paralyze', + value: 'paralyze', + label: 'Paralyze', + krLabel: '마비', + }, + { icon: 'feature-icons/stun', value: 'stun', label: 'Stun', krLabel: '기절' }, + { + icon: 'feature-icons/ignite', + value: 'ignite', + label: 'Ignite', + krLabel: '점화', + }, + { + icon: 'feature-icons/bleed', + value: 'bleed', + label: 'Bleed', + krLabel: '출혈', + }, + { + icon: 'feature-icons/heavy-atk', + value: 'heavy-atk', + label: 'Heavy ATK', + krLabel: '강타', + }, + { + icon: 'feature-icons/weaken', + value: 'weaken', + label: 'Weaken', + krLabel: '허약', + }, + { + icon: 'feature-icons/impair', + value: 'impair', + label: 'Impair', + krLabel: '취약', }, - { icon: 'feature-icons/freeze', value: 'freeze', label: 'Freeze' }, - { icon: 'feature-icons/paralyze', value: 'paralyze', label: 'Paralyze' }, - { icon: 'feature-icons/stun', value: 'stun', label: 'Stun' }, - { icon: 'feature-icons/ignite', value: 'ignite', label: 'Ignite' }, - { icon: 'feature-icons/bleed', value: 'bleed', label: 'Bleed' }, - { icon: 'feature-icons/heavy-atk', value: 'heavy-atk', label: 'Heavy ATK' }, - { icon: 'feature-icons/weaken', value: 'weaken', label: 'Weaken' }, - { icon: 'feature-icons/impair', value: 'impair', label: 'Impair' }, { icon: 'feature-icons/time-mastery', value: 'time mastery', label: 'Time Mastery', + krLabel: '시공', + }, + { + icon: 'feature-icons/gather', + value: 'gather', + label: 'Gather', + krLabel: '흡인', + }, + { icon: 'feature-icons/heal', value: 'heal', label: 'Heal', krLabel: '치료' }, + { + icon: 'feature-icons/fast-atk', + value: 'fast atk', + label: 'Fast ATK', + krLabel: '높은 빈도', + }, + { + icon: 'feature-icons/burst', + value: 'burst', + label: 'Burst', + krLabel: '폭발, 버스트', + }, + { + icon: 'feature-icons/aerial', + value: 'aerial', + label: 'Aerial', + krLabel: '대공', }, - { icon: 'feature-icons/gather', value: 'gather', label: 'Gather' }, - { icon: 'feature-icons/heal', value: 'heal', label: 'Heal' }, - { icon: 'feature-icons/fast-atk', value: 'fast atk', label: 'Fast ATK' }, - { icon: 'feature-icons/burst', value: 'burst', label: 'Burst' }, - { icon: 'feature-icons/aerial', value: 'aerial', label: 'Aerial' }, ] export const battlesuitTypes = [ - { value: 'mecha', icon: 'type-icons/mecha', label: 'Mecha' }, - { value: 'biologic', icon: 'type-icons/biologic', label: 'Biologic' }, - { value: 'psychic', icon: 'type-icons/psychic', label: 'Psychic' }, - { value: 'quantum', icon: 'type-icons/quantum', label: 'Quantum' }, - { value: 'imaginary', icon: 'type-icons/imaginary', label: 'Imaginary' }, + { value: 'mecha', icon: 'type-icons/mecha', label: 'Mecha', krLabel: '기계' }, + { + value: 'biologic', + icon: 'type-icons/biologic', + label: 'Biologic', + krLabel: '생물', + }, + { + value: 'psychic', + icon: 'type-icons/psychic', + label: 'Psychic', + krLabel: '이능', + }, + { + value: 'quantum', + icon: 'type-icons/quantum', + label: 'Quantum', + krLabel: '양자', + }, + { + value: 'imaginary', + icon: 'type-icons/imaginary', + label: 'Imaginary', + krLabel: '허수', + }, ] export const valkyries = [ - { value: 'kiana', icon: 'valkyrie-icons/kiana', label: 'Kiana' }, - { value: 'mei', icon: 'valkyrie-icons/mei', label: 'Mei' }, - { value: 'bronya', icon: 'valkyrie-icons/bronya', label: 'Bronya' }, - { value: 'himeko', icon: 'valkyrie-icons/himeko', label: 'Himeko' }, - { value: 'theresa', icon: 'valkyrie-icons/theresa', label: 'Theresa' }, - { value: 'fuhua', icon: 'valkyrie-icons/fuhua', label: 'Fu Hua' }, - { value: 'rita', icon: 'valkyrie-icons/rita', label: 'Rita' }, - { value: 'sakura', icon: 'valkyrie-icons/sakura', label: 'Sakura' }, - { value: 'kallen', icon: 'valkyrie-icons/kallen', label: 'Kallen' }, - { value: 'olenyevas', icon: 'valkyrie-icons/olenyevas', label: 'Olenyevas' }, - { value: 'seele', icon: 'valkyrie-icons/seele', label: 'Seele' }, - { value: 'durandal', icon: 'valkyrie-icons/durandal', label: 'Durandal' }, - { value: 'fischl', icon: 'valkyrie-icons/fischl', label: 'Fischl' }, - { value: 'elysia', icon: 'valkyrie-icons/elysia', label: 'Elysia' }, - { value: 'mobius', icon: 'valkyrie-icons/mobius', label: 'Mobius' }, - { value: 'raven', icon: 'valkyrie-icons/raven', label: 'Raven' }, - { value: 'carole', icon: 'valkyrie-icons/carole', label: 'Carole' }, + { + value: 'kiana', + icon: 'valkyrie-icons/kiana', + label: 'Kiana', + krLabel: '키아나', + }, + { value: 'mei', icon: 'valkyrie-icons/mei', label: 'Mei', krLabel: '메이' }, + { + value: 'bronya', + icon: 'valkyrie-icons/bronya', + label: 'Bronya', + krLabel: '브로냐', + }, + { + value: 'himeko', + icon: 'valkyrie-icons/himeko', + label: 'Himeko', + krLabel: '히메코', + }, + { + value: 'theresa', + icon: 'valkyrie-icons/theresa', + label: 'Theresa', + krLabel: '테레사', + }, + { + value: 'fuhua', + icon: 'valkyrie-icons/fuhua', + label: 'Fu Hua', + krLabel: '후카', + }, + { + value: 'rita', + icon: 'valkyrie-icons/rita', + label: 'Rita', + krLabel: '리타', + }, + { + value: 'sakura', + icon: 'valkyrie-icons/sakura', + label: 'Sakura', + krLabel: '야에 사쿠라', + }, + { + value: 'kallen', + icon: 'valkyrie-icons/kallen', + label: 'Kallen', + krLabel: '카렌', + }, + { + value: 'olenyevas', + icon: 'valkyrie-icons/olenyevas', + label: 'Olenyevas', + krLabel: '아린 자매', + }, + { + value: 'seele', + icon: 'valkyrie-icons/seele', + label: 'Seele', + krLabel: '제레', + }, + { + value: 'durandal', + icon: 'valkyrie-icons/durandal', + label: 'Durandal', + krLabel: '듀란달', + }, + { + value: 'fischl', + icon: 'valkyrie-icons/fischl', + label: 'Fischl', + krLabel: '피슬', + }, + { + value: 'elysia', + icon: 'valkyrie-icons/elysia', + label: 'Elysia', + krLabel: '엘리시아', + }, + { + value: 'mobius', + icon: 'valkyrie-icons/mobius', + label: 'Mobius', + krLabel: '뫼비우스', + }, + { + value: 'raven', + icon: 'valkyrie-icons/raven', + label: 'Raven', + krLabel: '레이븐', + }, + { + value: 'carole', + icon: 'valkyrie-icons/carole', + label: 'Carole', + krLabel: '캐롤', + }, ] diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts index 23bf7560..849867d6 100644 --- a/src/lib/i18n.ts +++ b/src/lib/i18n.ts @@ -1,17 +1,11 @@ -import { serverSideTranslations } from 'next-i18next/serverSideTranslations' +import { useTranslation } from 'next-i18next' -export function getI18NProps( - locale: string = 'en-US', - nameSpaces: string[] = [] -) { - return serverSideTranslations(locale, ['common', ...nameSpaces]) +export function translate( + targetLocale: string = 'en_US', + localeMap: { [key: string]: string | undefined }, + fallback: string +): string { + return localeMap[targetLocale] != null ? localeMap[targetLocale]! : fallback } -export function generateI18NPaths(paths: { params: any; locale?: string }[]) { - return paths.reduce<{ params: any; locale?: string }[]>((newPaths, path) => { - newPaths.push(path) - newPaths.push({ ...path, locale: 'ko-KR' }) - - return newPaths - }, []) -} +export { useTranslation } diff --git a/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx b/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx index b4bb3b82..6b5d8ef4 100644 --- a/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx +++ b/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx @@ -15,12 +15,12 @@ import { BattlesuitData, BattlesuitSkillGroup, } from '../../../lib/honkai3rd/battlesuits' -import { generateI18NPaths, getI18NProps } from '../../../lib/i18n' +import { generateI18NPaths, getI18NProps } from '../../../server/i18n' import { getBattlesuitById, listBattlesuits, } from '../../../server/data/honkai3rd/battlesuits' -import { useTranslation } from 'next-i18next' +import { useTranslation } from '../../../lib/i18n' interface BattlesuitShowPageProps { battlesuit: BattlesuitData diff --git a/src/pages/honkai3rd/battlesuits/index.tsx b/src/pages/honkai3rd/battlesuits/index.tsx index 22313ddd..369fb8d7 100644 --- a/src/pages/honkai3rd/battlesuits/index.tsx +++ b/src/pages/honkai3rd/battlesuits/index.tsx @@ -15,7 +15,8 @@ import { import BattlesuitCard from '../../../components/molecules/BattlesuitCard' import { useRouter } from 'next/router' import { NextPageContext } from 'next' -import { getI18NProps } from '../../../lib/i18n' +import { getI18NProps } from '../../../server/i18n' +import { translate, useTranslation } from '../../../lib/i18n' type BattlesuitListItemData = Pick< BattlesuitData, @@ -26,14 +27,27 @@ interface BattlesuitListPageProps { battlesuits: BattlesuitListItemData[] } -const featureFilterOptions: { value: string; label: string; icon?: string }[] = - [{ value: 'all', label: 'All' }, ...battlesuitFeatures] +const featureFilterOptions: { + value: string + label: string + icon?: string + krLabel?: string +}[] = [{ value: 'all', label: 'All', krLabel: '전체' }, ...battlesuitFeatures] -const valkyrieFilterOptions: { value: string; label: string; icon?: string }[] = - [{ value: 'all', label: 'All' }, ...battlesuitTypes, ...valkyries] +const valkyrieFilterOptions: { + value: string + label: string + icon?: string + krLabel?: string +}[] = [ + { value: 'all', label: 'All', krLabel: '전체' }, + ...battlesuitTypes, + ...valkyries, +] const BattlesuitListPage = ({ battlesuits }: BattlesuitListPageProps) => { - const { query } = useRouter() + const { query, locale } = useRouter() + const { t } = useTranslation() const filter = useMemo(() => { if (query.filter == null) { @@ -63,23 +77,26 @@ const BattlesuitListPage = ({ battlesuits }: BattlesuitListPageProps) => { - Battlesuits + {t('battlesuits-list.heading')} - Filter by Features + {t('battlesuits-list.filter-by-features')} - {featureFilterOptions.map(({ value, label, icon }) => { + {featureFilterOptions.map(({ value, label, icon, krLabel }) => { return ( @@ -87,15 +104,15 @@ const BattlesuitListPage = ({ battlesuits }: BattlesuitListPageProps) => { })} - Filter by Valkyries + {t('battlesuits-list.filter-by-valkyries')} - {valkyrieFilterOptions.map(({ value, label, icon }) => { + {valkyrieFilterOptions.map(({ value, label, icon, krLabel }) => { return ( diff --git a/src/pages/honkai3rd/elfs/[elfId].tsx b/src/pages/honkai3rd/elfs/[elfId].tsx index ae390e85..dae8298b 100644 --- a/src/pages/honkai3rd/elfs/[elfId].tsx +++ b/src/pages/honkai3rd/elfs/[elfId].tsx @@ -8,9 +8,9 @@ import SecondaryLabel from '../../../components/atoms/SecondaryLabel' import Breadcrumb from '../../../components/organisms/Breadcrumb' import Honkai3rdNavigator from '../../../components/organisms/Honkai3rdNavigator' import { ElfData } from '../../../lib/honkai3rd/elfs' -import { generateI18NPaths, getI18NProps } from '../../../lib/i18n' import { capitalize } from '../../../lib/string' import { getElfById, listElfs } from '../../../server/data/honkai3rd/elfs' +import { generateI18NPaths, getI18NProps } from '../../../server/i18n' interface ElfShowPageProps { elf: ElfData diff --git a/src/pages/honkai3rd/elfs/index.tsx b/src/pages/honkai3rd/elfs/index.tsx index c0921009..0adbbaa8 100644 --- a/src/pages/honkai3rd/elfs/index.tsx +++ b/src/pages/honkai3rd/elfs/index.tsx @@ -6,7 +6,7 @@ import ElfCard from '../../../components/molecules/ElfCard' import Breadcrumb from '../../../components/organisms/Breadcrumb' import Honkai3rdNavigator from '../../../components/organisms/Honkai3rdNavigator' import { ElfData } from '../../../lib/honkai3rd/elfs' -import { getI18NProps } from '../../../lib/i18n' +import { getI18NProps } from '../../../server/i18n' import { listElfs } from '../../../server/data/honkai3rd/elfs' interface ElfListPageProps { diff --git a/src/pages/honkai3rd/index.tsx b/src/pages/honkai3rd/index.tsx index b8a987bc..3d169327 100644 --- a/src/pages/honkai3rd/index.tsx +++ b/src/pages/honkai3rd/index.tsx @@ -5,7 +5,7 @@ import NextLink from 'next/link' import Breadcrumb from '../../components/organisms/Breadcrumb' import Honkai3rdNavigator from '../../components/organisms/Honkai3rdNavigator' import { NextPageContext } from 'next' -import { getI18NProps } from '../../lib/i18n' +import { getI18NProps } from '../../server/i18n' const updateNotes = [ ['v5.3', 'https://honkaiimpact3.mihoyo.com/global/en-us/news/17390'], diff --git a/src/pages/honkai3rd/stigmata/[stigmataId].tsx b/src/pages/honkai3rd/stigmata/[stigmataId].tsx index 04192484..871d3494 100644 --- a/src/pages/honkai3rd/stigmata/[stigmataId].tsx +++ b/src/pages/honkai3rd/stigmata/[stigmataId].tsx @@ -6,7 +6,7 @@ import SingleStigmataPage, { import StigmataSetPage, { StigmataSetProps, } from '../../../components/pages/StigmataSetPage' -import { generateI18NPaths, getI18NProps } from '../../../lib/i18n' +import { generateI18NPaths, getI18NProps } from '../../../server/i18n' import { listStigmata, getStigmataById, diff --git a/src/pages/honkai3rd/stigmata/index.tsx b/src/pages/honkai3rd/stigmata/index.tsx index 152483c1..bc4a7ba7 100644 --- a/src/pages/honkai3rd/stigmata/index.tsx +++ b/src/pages/honkai3rd/stigmata/index.tsx @@ -10,7 +10,7 @@ import StigmataSetCard from '../../../components/molecules/StigmataSetCard' import Breadcrumb from '../../../components/organisms/Breadcrumb' import Honkai3rdNavigator from '../../../components/organisms/Honkai3rdNavigator' import { StigmataData, StigmataSet } from '../../../lib/honkai3rd/stigmata' -import { getI18NProps } from '../../../lib/i18n' +import { getI18NProps } from '../../../server/i18n' import { listStigmata, listStigmataSet, diff --git a/src/pages/honkai3rd/versions/[versionId].tsx b/src/pages/honkai3rd/versions/[versionId].tsx index d8ff778d..5ba6732c 100644 --- a/src/pages/honkai3rd/versions/[versionId].tsx +++ b/src/pages/honkai3rd/versions/[versionId].tsx @@ -20,7 +20,7 @@ import { BattlesuitData } from '../../../lib/honkai3rd/battlesuits' import { WeaponData } from '../../../lib/honkai3rd/weapons' import { SupplyEventData } from '../../../lib/honkai3rd/supplyEvents' import { VersionData } from '../../../lib/honkai3rd/versions' -import { generateI18NPaths, getI18NProps } from '../../../lib/i18n' +import { generateI18NPaths, getI18NProps } from '../../../server/i18n' interface VersionShowPageProps { versionData: VersionData diff --git a/src/pages/honkai3rd/versions/index.tsx b/src/pages/honkai3rd/versions/index.tsx index 933b182e..bb5211d6 100644 --- a/src/pages/honkai3rd/versions/index.tsx +++ b/src/pages/honkai3rd/versions/index.tsx @@ -19,7 +19,7 @@ import { BattlesuitData } from '../../../lib/honkai3rd/battlesuits' import { WeaponData } from '../../../lib/honkai3rd/weapons' import { VersionData } from '../../../lib/honkai3rd/versions' import { SupplyEventData } from '../../../lib/honkai3rd/supplyEvents' -import { getI18NProps } from '../../../lib/i18n' +import { getI18NProps } from '../../../server/i18n' import { NextPageContext } from 'next' interface VersionIndexPageProps { diff --git a/src/pages/honkai3rd/weapons/[weaponId].tsx b/src/pages/honkai3rd/weapons/[weaponId].tsx index 8107e7f6..091a9f96 100644 --- a/src/pages/honkai3rd/weapons/[weaponId].tsx +++ b/src/pages/honkai3rd/weapons/[weaponId].tsx @@ -5,7 +5,7 @@ import SquareImageBox from '../../../components/atoms/SquareImageBox' import Breadcrumb from '../../../components/organisms/Breadcrumb' import Honkai3rdNavigator from '../../../components/organisms/Honkai3rdNavigator' import { WeaponData } from '../../../lib/honkai3rd/weapons' -import { generateI18NPaths, getI18NProps } from '../../../lib/i18n' +import { generateI18NPaths, getI18NProps } from '../../../server/i18n' import { capitalize } from '../../../lib/string' import { getWeaponById, diff --git a/src/pages/honkai3rd/weapons/index.tsx b/src/pages/honkai3rd/weapons/index.tsx index d473c330..b5307433 100644 --- a/src/pages/honkai3rd/weapons/index.tsx +++ b/src/pages/honkai3rd/weapons/index.tsx @@ -9,7 +9,7 @@ import FilterButton from '../../../components/atoms/FilterButton' import { useRouter } from 'next/router' import { WeaponData } from '../../../lib/honkai3rd/weapons' import WeaponCard from '../../../components/molecules/WeaponCard' -import { getI18NProps } from '../../../lib/i18n' +import { getI18NProps } from '../../../server/i18n' import { NextPageContext } from 'next' type WeaponListItemData = Pick< diff --git a/src/server/i18n.ts b/src/server/i18n.ts new file mode 100644 index 00000000..23bf7560 --- /dev/null +++ b/src/server/i18n.ts @@ -0,0 +1,17 @@ +import { serverSideTranslations } from 'next-i18next/serverSideTranslations' + +export function getI18NProps( + locale: string = 'en-US', + nameSpaces: string[] = [] +) { + return serverSideTranslations(locale, ['common', ...nameSpaces]) +} + +export function generateI18NPaths(paths: { params: any; locale?: string }[]) { + return paths.reduce<{ params: any; locale?: string }[]>((newPaths, path) => { + newPaths.push(path) + newPaths.push({ ...path, locale: 'ko-KR' }) + + return newPaths + }, []) +}