From 8bc576208a36d9b979213e19f724288970da42ed Mon Sep 17 00:00:00 2001 From: Sakura Knoll Date: Mon, 3 Jan 2022 13:22:37 +0900 Subject: [PATCH] Introduce i18n --- next-i18next.config.js | 7 ++ next.config.js | 5 ++ package-lock.json | 76 +++++++++++++++++-- package.json | 1 + public/locales/en-US/common.json | 9 +++ public/locales/ko-KR/common.json | 10 +++ .../organisms/Honkai3rdNavigator.tsx | 26 +++++-- src/lib/i18n.ts | 8 ++ src/pages/_app.tsx | 3 +- .../honkai3rd/battlesuits/[battlesuitId].tsx | 12 +-- src/pages/honkai3rd/battlesuits/index.tsx | 5 +- src/pages/honkai3rd/elfs/[elfId].tsx | 12 +-- src/pages/honkai3rd/elfs/index.tsx | 5 +- src/pages/honkai3rd/index.tsx | 33 +++----- src/pages/honkai3rd/stigmata/[stigmataId].tsx | 13 ++-- src/pages/honkai3rd/stigmata/index.tsx | 5 +- src/pages/honkai3rd/versions/[versionId].tsx | 3 + src/pages/honkai3rd/versions/index.tsx | 5 +- src/pages/honkai3rd/weapons/[weaponId].tsx | 13 ++-- src/pages/honkai3rd/weapons/index.tsx | 5 +- 20 files changed, 198 insertions(+), 58 deletions(-) create mode 100644 next-i18next.config.js create mode 100644 next.config.js create mode 100644 public/locales/en-US/common.json create mode 100644 public/locales/ko-KR/common.json create mode 100644 src/lib/i18n.ts diff --git a/next-i18next.config.js b/next-i18next.config.js new file mode 100644 index 00000000..6fd80b6e --- /dev/null +++ b/next-i18next.config.js @@ -0,0 +1,7 @@ +module.exports = { + i18n: { + locales: ['en-US', 'ko-KR'], + defaultLocale: 'en-US', + }, + reloadOnPrerender: true, +} diff --git a/next.config.js b/next.config.js new file mode 100644 index 00000000..09374ad3 --- /dev/null +++ b/next.config.js @@ -0,0 +1,5 @@ +const { i18n } = require('./next-i18next.config') + +module.exports = { + i18n, +} diff --git a/package-lock.json b/package-lock.json index 728c5132..237dd14a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -735,6 +735,15 @@ "@theme-ui/mdx": "0.12.1" } }, + "@types/hoist-non-react-statics": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz", + "integrity": "sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==", + "requires": { + "@types/react": "*", + "hoist-non-react-statics": "^3.3.0" + } + }, "@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", @@ -754,8 +763,7 @@ "@types/prop-types": { "version": "15.7.4", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.4.tgz", - "integrity": "sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ==", - "dev": true + "integrity": "sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ==" }, "@types/ramda": { "version": "0.27.60", @@ -770,7 +778,6 @@ "version": "17.0.37", "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.37.tgz", "integrity": "sha512-2FS1oTqBGcH/s0E+CjrCCR9+JMpsu9b69RTFO+40ua43ZqP5MmQ4iUde/dMjWR909KxZwmOQIFq6AV6NjEG5xg==", - "dev": true, "requires": { "@types/prop-types": "*", "@types/scheduler": "*", @@ -780,8 +787,7 @@ "@types/scheduler": { "version": "0.16.2", "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", - "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==", - "dev": true + "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==" }, "@types/styled-system": { "version": "5.1.13", @@ -1321,6 +1327,11 @@ } } }, + "core-js": { + "version": "3.20.2", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.20.2.tgz", + "integrity": "sha512-nuqhq11DcOAbFBV4zCbKeGbKQsUDRqTX0oqx7AttUBuqe3h20ixsE039QHelbL6P4h+9kytVqyEtyZ6gsiwEYw==" + }, "core-js-pure": { "version": "3.20.0", "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.20.0.tgz", @@ -2468,6 +2479,19 @@ } } }, + "html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==" + }, + "html-parse-stringify": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/html-parse-stringify/-/html-parse-stringify-3.0.1.tgz", + "integrity": "sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg==", + "requires": { + "void-elements": "3.1.0" + } + }, "http-errors": { "version": "1.7.3", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.3.tgz", @@ -2485,6 +2509,19 @@ "resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-1.0.0.tgz", "integrity": "sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=" }, + "i18next": { + "version": "21.6.4", + "resolved": "https://registry.npmjs.org/i18next/-/i18next-21.6.4.tgz", + "integrity": "sha512-pk0Utxtq5g//Q9ONQ0w3+PRSwOFJ7+m4rAekhHHg1Xql0KcUjJU7DzmzweGy6DsrIQ1GM/t57wLeeGuyGKtjTg==", + "requires": { + "@babel/runtime": "^7.12.0" + } + }, + "i18next-fs-backend": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/i18next-fs-backend/-/i18next-fs-backend-1.1.4.tgz", + "integrity": "sha512-/MfAGMP0jHonV966uFf9PkWWuDjPYLIcsipnSO3NxpNtAgRUKLTwvm85fEmsF6hGeu0zbZiCQ3W74jwO6K9uXA==" + }, "iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", @@ -3028,6 +3065,20 @@ "watchpack": "2.3.0" } }, + "next-i18next": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/next-i18next/-/next-i18next-10.1.0.tgz", + "integrity": "sha512-KvrXiSLRjsJrP8Uv+MFNuTXk1tlwaktce+3yTDtYqh/75BExLmV4Dr9om+zhAz8P+yMke5yhmR2Lnl0FV6mhsQ==", + "requires": { + "@babel/runtime": "^7.13.17", + "@types/hoist-non-react-statics": "^3.3.1", + "core-js": "^3", + "hoist-non-react-statics": "^3.2.0", + "i18next": "^21.5.3", + "i18next-fs-backend": "^1.0.7", + "react-i18next": "^11.8.13" + } + }, "node-fetch": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", @@ -3450,6 +3501,16 @@ "scheduler": "^0.20.2" } }, + "react-i18next": { + "version": "11.15.3", + "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-11.15.3.tgz", + "integrity": "sha512-RSUEM4So3Tu2JHV0JsZ5Yje+4nz66YViMfPZoywxOy0xyn3L7tE2CHvJ7Y9LUsrTU7vGmZ5bwb8PpjnkatdIxg==", + "requires": { + "@babel/runtime": "^7.14.5", + "html-escaper": "^2.0.2", + "html-parse-stringify": "^3.0.1" + } + }, "react-indiana-drag-scroll": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/react-indiana-drag-scroll/-/react-indiana-drag-scroll-2.1.0.tgz", @@ -3984,6 +4045,11 @@ "resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-1.1.2.tgz", "integrity": "sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ==" }, + "void-elements": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-3.1.0.tgz", + "integrity": "sha1-YU9/v42AHwu18GYfWy9XhXUOTwk=" + }, "watchpack": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.3.0.tgz", diff --git a/package.json b/package.json index 2272abc1..50dc412c 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "@mdi/react": "^1.5.0", "date-fns": "^2.27.0", "next": "^12.0.7", + "next-i18next": "^10.1.0", "open-color": "^1.9.1", "ramda": "^0.27.1", "react": "^17.0.2", diff --git a/public/locales/en-US/common.json b/public/locales/en-US/common.json new file mode 100644 index 00000000..93f1b317 --- /dev/null +++ b/public/locales/en-US/common.json @@ -0,0 +1,9 @@ +{ + "nav": { + "versions": "Versions", + "battlesuits": "Battlesuits", + "weapons": "Weapons", + "stigmata": "Stigmata", + "elfs": "ELFs" + } +} diff --git a/public/locales/ko-KR/common.json b/public/locales/ko-KR/common.json new file mode 100644 index 00000000..15a6a047 --- /dev/null +++ b/public/locales/ko-KR/common.json @@ -0,0 +1,10 @@ +{ + "nav": { + "honkai-3rd": "붕괴 3rd", + "versions": "업데이트", + "battlesuits": "발키리", + "weapons": "무기", + "stigmata": "성흔", + "elfs": "무장인형" + } +} diff --git a/src/components/organisms/Honkai3rdNavigator.tsx b/src/components/organisms/Honkai3rdNavigator.tsx index 2d50d9a0..b5883a75 100644 --- a/src/components/organisms/Honkai3rdNavigator.tsx +++ b/src/components/organisms/Honkai3rdNavigator.tsx @@ -1,8 +1,14 @@ /** @jsxImportSource theme-ui */ import { NavLink, Heading, Flex } from '@theme-ui/components' import NextLink from 'next/link' +import { useRouter } from 'next/router' +import { useTranslation } from 'next-i18next' const Honkai3rdNavigator = () => { + const router = useRouter() + const { pathname, asPath, query, locale } = router + const { t } = useTranslation() + return ( @@ -12,36 +18,44 @@ const Honkai3rdNavigator = () => { : - Honkai 3rd + {t('nav.honkai-3rd')} - Versions + {t('nav.versions')} - Battlesuits + {t('nav.battlesuits')} - Weapons + {t('nav.weapons')} - Stigmata + {t('nav.stigmata')} - ELFs + {t('nav.elfs')} + + {locale === 'en-US' ? '🇺🇸' : '🇰🇷'} + ) diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts new file mode 100644 index 00000000..4c4172fa --- /dev/null +++ b/src/lib/i18n.ts @@ -0,0 +1,8 @@ +import { serverSideTranslations } from 'next-i18next/serverSideTranslations' + +export function getI18NProps( + locale: string = 'en-US', + nameSpaces: string[] = [] +) { + return serverSideTranslations(locale, ['common', ...nameSpaces]) +} diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index f889af85..62fc12c5 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -1,4 +1,5 @@ import type { AppProps } from 'next/app' +import { appWithTranslation } from 'next-i18next' import { ThemeProvider } from 'theme-ui' import { theme } from '../lib/theme' @@ -10,4 +11,4 @@ function MyApp({ Component, pageProps }: AppProps) { ) } -export default MyApp +export default appWithTranslation(MyApp) diff --git a/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx b/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx index 74d7c89f..56a91d6a 100644 --- a/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx +++ b/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx @@ -15,6 +15,7 @@ import { BattlesuitData, BattlesuitSkillGroup, } from '../../../lib/honkai3rd/battlesuits' +import { getI18NProps } from '../../../lib/i18n' import { getBattlesuitById, listBattlesuits, @@ -149,12 +150,13 @@ const BattlesuitShowPage = ({ battlesuit }: BattlesuitShowPageProps) => { export default BattlesuitShowPage -export function getStaticProps( - context: NextPageContext & { params: { battlesuitId: string } } -) { - const battlesuit = getBattlesuitById(context.params.battlesuitId) +export async function getStaticProps({ + params, + locale, +}: NextPageContext & { params: { battlesuitId: string } }) { + const battlesuit = getBattlesuitById(params.battlesuitId) return { - props: { battlesuit }, + props: { battlesuit, ...(await getI18NProps(locale)) }, } } diff --git a/src/pages/honkai3rd/battlesuits/index.tsx b/src/pages/honkai3rd/battlesuits/index.tsx index b0bc3fa1..22313ddd 100644 --- a/src/pages/honkai3rd/battlesuits/index.tsx +++ b/src/pages/honkai3rd/battlesuits/index.tsx @@ -14,6 +14,8 @@ import { } from '../../../lib/honkai3rd/battlesuits' import BattlesuitCard from '../../../components/molecules/BattlesuitCard' import { useRouter } from 'next/router' +import { NextPageContext } from 'next' +import { getI18NProps } from '../../../lib/i18n' type BattlesuitListItemData = Pick< BattlesuitData, @@ -117,12 +119,13 @@ const BattlesuitListPage = ({ battlesuits }: BattlesuitListPageProps) => { export default BattlesuitListPage -export async function getStaticProps() { +export async function getStaticProps({ locale }: NextPageContext) { return { props: { battlesuits: listBattlesuits().map((battlesuit) => pick(['id', 'name', 'features', 'type', 'valkyrie'], battlesuit) ), + ...(await getI18NProps(locale)), }, } } diff --git a/src/pages/honkai3rd/elfs/[elfId].tsx b/src/pages/honkai3rd/elfs/[elfId].tsx index da9bbd1e..85fee973 100644 --- a/src/pages/honkai3rd/elfs/[elfId].tsx +++ b/src/pages/honkai3rd/elfs/[elfId].tsx @@ -8,6 +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 { capitalize } from '../../../lib/string' import { getElfById, listElfs } from '../../../server/data/honkai3rd/elfs' @@ -103,12 +104,13 @@ const ElfShowPage = ({ elf }: ElfShowPageProps) => { export default ElfShowPage -export function getStaticProps( - context: NextPageContext & { params: { elfId: string } } -) { - const elf = getElfById(context.params.elfId) +export async function getStaticProps({ + params, + locale, +}: NextPageContext & { params: { elfId: string } }) { + const elf = getElfById(params.elfId) return { - props: { elf }, + props: { elf, ...(await getI18NProps(locale)) }, } } diff --git a/src/pages/honkai3rd/elfs/index.tsx b/src/pages/honkai3rd/elfs/index.tsx index 5a20499c..c0921009 100644 --- a/src/pages/honkai3rd/elfs/index.tsx +++ b/src/pages/honkai3rd/elfs/index.tsx @@ -1,10 +1,12 @@ /** @jsxImportSource theme-ui */ import { Box, Heading, Flex } from '@theme-ui/components' +import { NextPageContext } from 'next' import { pick } from 'ramda' 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 { listElfs } from '../../../server/data/honkai3rd/elfs' interface ElfListPageProps { @@ -43,10 +45,11 @@ const ElfListPage = ({ elfs }: ElfListPageProps) => { export default ElfListPage -export async function getStaticProps() { +export async function getStaticProps({ locale }: NextPageContext) { return { props: { elfs: listElfs().map((elf) => pick(['id', 'name'], elf)), + ...(await getI18NProps(locale)), }, } } diff --git a/src/pages/honkai3rd/index.tsx b/src/pages/honkai3rd/index.tsx index 94afc3ad..b8a987bc 100644 --- a/src/pages/honkai3rd/index.tsx +++ b/src/pages/honkai3rd/index.tsx @@ -4,29 +4,12 @@ import Image from 'next/image' 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' const updateNotes = [ - ['v5.3', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/17399'], - ['v5.2', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/16632'], - ['v5.1', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/15882'], - ['v5.0', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/14917'], - ['v4.9', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/13943'], - ['v4.8', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/13044'], - ['v4.7', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/11980'], - ['v4.6', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/9101'], - ['v4.5', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/7996'], - ['v4.4', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/7312'], - ['v4.3', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/6105'], - ['v4.2', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/5489'], - ['v4.1', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/4965'], - ['v4.0', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/4421'], - ['v3.9', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/3296'], - ['v3.8', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/2855'], - ['v3.7', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/2337'], - ['v3.6', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/1936'], - ['v3.5', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/1505'], - ['v3.4', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/1092'], - ['v3.3', 'https://honkaiimpact3.mihoyo.com/asia/en-us/news/851'], + ['v5.3', 'https://honkaiimpact3.mihoyo.com/global/en-us/news/17390'], + ['v5.2', 'https://honkaiimpact3.mihoyo.com/global/en-us/news/16625'], ] const Honkai3rdIndexPage = () => { @@ -82,4 +65,12 @@ const Honkai3rdIndexPage = () => { ) } +export async function getStaticProps({ locale }: NextPageContext) { + return { + props: { + ...(await getI18NProps(locale)), + }, + } +} + export default Honkai3rdIndexPage diff --git a/src/pages/honkai3rd/stigmata/[stigmataId].tsx b/src/pages/honkai3rd/stigmata/[stigmataId].tsx index 658ffc41..51f8a184 100644 --- a/src/pages/honkai3rd/stigmata/[stigmataId].tsx +++ b/src/pages/honkai3rd/stigmata/[stigmataId].tsx @@ -6,6 +6,7 @@ import SingleStigmataPage, { import StigmataSetPage, { StigmataSetProps, } from '../../../components/pages/StigmataSetPage' +import { getI18NProps } from '../../../lib/i18n' import { listStigmata, getStigmataById, @@ -26,10 +27,11 @@ const StigmataListPage = (props: StigmataShowPageProps) => { export default StigmataListPage -export async function getStaticProps( - ctx: NextPageContext & { params: { stigmataId: string } } -) { - const stigmataData = getStigmataById(ctx.params.stigmataId)! +export async function getStaticProps({ + params, + locale, +}: NextPageContext & { params: { stigmataId: string } }) { + const stigmataData = getStigmataById(params.stigmataId)! if (stigmataData != null) { return { props: { @@ -42,7 +44,7 @@ export async function getStaticProps( }, } } - const [stigmataSetId] = ctx.params.stigmataId.split('-set') + const [stigmataSetId] = params.stigmataId.split('-set') const stigmataSet = getStigmataSetBySetId(stigmataSetId)! return { props: { @@ -51,6 +53,7 @@ export async function getStaticProps( stigmataSetList: (getStigmataListBySetId(stigmataSet.id) || []).sort( (a, b) => -a.type.localeCompare(b.type) ), + ...(await getI18NProps(locale)), }, } } diff --git a/src/pages/honkai3rd/stigmata/index.tsx b/src/pages/honkai3rd/stigmata/index.tsx index d4f93498..152483c1 100644 --- a/src/pages/honkai3rd/stigmata/index.tsx +++ b/src/pages/honkai3rd/stigmata/index.tsx @@ -1,5 +1,6 @@ /** @jsxImportSource theme-ui */ import { Box, Heading, Flex } from '@theme-ui/components' +import { NextPageContext } from 'next' import { useRouter } from 'next/router' import { pick } from 'ramda' import { useMemo } from 'react' @@ -9,6 +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 { listStigmata, listStigmataSet, @@ -89,7 +91,7 @@ const StigmataListPage = ({ export default StigmataListPage -export async function getStaticProps() { +export async function getStaticProps({ locale }: NextPageContext) { return { props: { stigmataDataList: listStigmata().map((stigmata) => @@ -98,6 +100,7 @@ export async function getStaticProps() { stigmataSetList: listStigmataSet().map((stigmataSet) => pick(['id', 'name', 'rarity'], stigmataSet) ), + ...(await getI18NProps(locale)), }, } } diff --git a/src/pages/honkai3rd/versions/[versionId].tsx b/src/pages/honkai3rd/versions/[versionId].tsx index f0528de6..d582b96c 100644 --- a/src/pages/honkai3rd/versions/[versionId].tsx +++ b/src/pages/honkai3rd/versions/[versionId].tsx @@ -20,6 +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' interface VersionShowPageProps { versionData: VersionData @@ -186,6 +187,7 @@ export default VersionShowPage export async function getStaticProps({ params, + locale, }: NextPageContext & { params: { versionId: string } }) { const versionData = getVersion(params.versionId)! @@ -204,6 +206,7 @@ export async function getStaticProps({ battlesuits, weapons, supplyEvents, + ...(await getI18NProps(locale)), }, } } diff --git a/src/pages/honkai3rd/versions/index.tsx b/src/pages/honkai3rd/versions/index.tsx index 05f50a78..933b182e 100644 --- a/src/pages/honkai3rd/versions/index.tsx +++ b/src/pages/honkai3rd/versions/index.tsx @@ -19,6 +19,8 @@ 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 { NextPageContext } from 'next' interface VersionIndexPageProps { versionDataList: VersionData[] @@ -216,7 +218,7 @@ const VersionIndexPage = ({ ) } -export async function getStaticProps() { +export async function getStaticProps({ locale }: NextPageContext) { const currentVersionData = getCurrentVersion()! const currentVersionNewBattlesuits = currentVersionData.newBattlesuits.map( @@ -241,6 +243,7 @@ export async function getStaticProps() { currentVersionNewWeapons, currentVersionSupplyEvents, versionDataList: listVersionData(), + ...(await getI18NProps(locale)), }, } } diff --git a/src/pages/honkai3rd/weapons/[weaponId].tsx b/src/pages/honkai3rd/weapons/[weaponId].tsx index fc22e6d6..bda40bdc 100644 --- a/src/pages/honkai3rd/weapons/[weaponId].tsx +++ b/src/pages/honkai3rd/weapons/[weaponId].tsx @@ -5,6 +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 { capitalize } from '../../../lib/string' import { getWeaponById, @@ -80,12 +81,14 @@ const WeaponShowPage = ({ weapon }: WeaponShowPageProps) => { export default WeaponShowPage -export function getStaticProps( - context: NextPageContext & { params: { weaponId: string } } -) { - const weapon = getWeaponById(context.params.weaponId) +export async function getStaticProps({ + params, + locale, +}: NextPageContext & { params: { weaponId: string } }) { + const weapon = getWeaponById(params.weaponId) + return { - props: { weapon }, + props: { weapon, ...(await getI18NProps(locale)) }, } } diff --git a/src/pages/honkai3rd/weapons/index.tsx b/src/pages/honkai3rd/weapons/index.tsx index d1d3ce63..d473c330 100644 --- a/src/pages/honkai3rd/weapons/index.tsx +++ b/src/pages/honkai3rd/weapons/index.tsx @@ -9,6 +9,8 @@ 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 { NextPageContext } from 'next' type WeaponListItemData = Pick< WeaponData, @@ -94,12 +96,13 @@ const WeaponListPage = ({ weaponDataList }: WeaponListPageProps) => { export default WeaponListPage -export async function getStaticProps() { +export async function getStaticProps({ locale }: NextPageContext) { return { props: { weaponDataList: listWeapons().map((weapon) => { return pick(['name', 'id', 'rarity', 'category'], weapon) }), + ...(await getI18NProps(locale)), }, } }