diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts index 4c4172fa..23bf7560 100644 --- a/src/lib/i18n.ts +++ b/src/lib/i18n.ts @@ -6,3 +6,12 @@ export function getI18NProps( ) { 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 + }, []) +} diff --git a/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx b/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx index 56a91d6a..b4bb3b82 100644 --- a/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx +++ b/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx @@ -15,17 +15,19 @@ import { BattlesuitData, BattlesuitSkillGroup, } from '../../../lib/honkai3rd/battlesuits' -import { getI18NProps } from '../../../lib/i18n' +import { generateI18NPaths, getI18NProps } from '../../../lib/i18n' import { getBattlesuitById, listBattlesuits, } from '../../../server/data/honkai3rd/battlesuits' +import { useTranslation } from 'next-i18next' interface BattlesuitShowPageProps { battlesuit: BattlesuitData } const BattlesuitShowPage = ({ battlesuit }: BattlesuitShowPageProps) => { + const { t } = useTranslation() return ( @@ -33,8 +35,11 @@ const BattlesuitShowPage = ({ battlesuit }: BattlesuitShowPageProps) => { { - return { - params: { battlesuitId: battlesuit.id }, - } - }), + paths: generateI18NPaths( + listBattlesuits().map((battlesuit) => { + return { + params: { battlesuitId: battlesuit.id }, + } + }) + ), fallback: false, } } diff --git a/src/pages/honkai3rd/elfs/[elfId].tsx b/src/pages/honkai3rd/elfs/[elfId].tsx index 85fee973..ae390e85 100644 --- a/src/pages/honkai3rd/elfs/[elfId].tsx +++ b/src/pages/honkai3rd/elfs/[elfId].tsx @@ -8,7 +8,7 @@ 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 { getI18NProps } from '../../../lib/i18n' +import { generateI18NPaths, getI18NProps } from '../../../lib/i18n' import { capitalize } from '../../../lib/string' import { getElfById, listElfs } from '../../../server/data/honkai3rd/elfs' @@ -116,11 +116,13 @@ export async function getStaticProps({ export async function getStaticPaths() { return { - paths: listElfs().map((elf) => { - return { - params: { elfId: elf.id }, - } - }), + paths: generateI18NPaths( + listElfs().map((elf) => { + return { + params: { elfId: elf.id }, + } + }) + ), fallback: false, } } diff --git a/src/pages/honkai3rd/stigmata/[stigmataId].tsx b/src/pages/honkai3rd/stigmata/[stigmataId].tsx index 51f8a184..04192484 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 { getI18NProps } from '../../../lib/i18n' +import { generateI18NPaths, getI18NProps } from '../../../lib/i18n' import { listStigmata, getStigmataById, @@ -60,7 +60,7 @@ export async function getStaticProps({ export async function getStaticPaths() { return { - paths: [ + paths: generateI18NPaths([ ...listStigmata().map((stigmata) => { return { params: { stigmataId: stigmata.id }, @@ -71,7 +71,7 @@ export async function getStaticPaths() { params: { stigmataId: `${stigmataSet.id}-set` }, } }), - ], + ]), fallback: false, } } diff --git a/src/pages/honkai3rd/versions/[versionId].tsx b/src/pages/honkai3rd/versions/[versionId].tsx index d582b96c..d8ff778d 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 { getI18NProps } from '../../../lib/i18n' +import { generateI18NPaths, getI18NProps } from '../../../lib/i18n' interface VersionShowPageProps { versionData: VersionData @@ -213,13 +213,15 @@ export async function getStaticProps({ export async function getStaticPaths() { return { - paths: listVersionData().map((versionData) => { - return { - params: { - versionId: versionData.version.toString(), - }, - } - }), + paths: generateI18NPaths( + listVersionData().map((versionData) => { + return { + params: { + versionId: versionData.version.toString(), + }, + } + }) + ), fallback: false, } } diff --git a/src/pages/honkai3rd/weapons/[weaponId].tsx b/src/pages/honkai3rd/weapons/[weaponId].tsx index bda40bdc..8107e7f6 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 { getI18NProps } from '../../../lib/i18n' +import { generateI18NPaths, getI18NProps } from '../../../lib/i18n' import { capitalize } from '../../../lib/string' import { getWeaponById, @@ -94,11 +94,13 @@ export async function getStaticProps({ export async function getStaticPaths() { return { - paths: listWeapons().map((weapon) => { - return { - params: { weaponId: weapon.id }, - } - }), + paths: generateI18NPaths( + listWeapons().map((weapon) => { + return { + params: { weaponId: weapon.id }, + } + }) + ), fallback: false, } }