Add localized paths
This commit is contained in:
@@ -6,3 +6,12 @@ export function getI18NProps(
|
|||||||
) {
|
) {
|
||||||
return serverSideTranslations(locale, ['common', ...nameSpaces])
|
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
|
||||||
|
}, [])
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,17 +15,19 @@ import {
|
|||||||
BattlesuitData,
|
BattlesuitData,
|
||||||
BattlesuitSkillGroup,
|
BattlesuitSkillGroup,
|
||||||
} from '../../../lib/honkai3rd/battlesuits'
|
} from '../../../lib/honkai3rd/battlesuits'
|
||||||
import { getI18NProps } from '../../../lib/i18n'
|
import { generateI18NPaths, getI18NProps } from '../../../lib/i18n'
|
||||||
import {
|
import {
|
||||||
getBattlesuitById,
|
getBattlesuitById,
|
||||||
listBattlesuits,
|
listBattlesuits,
|
||||||
} from '../../../server/data/honkai3rd/battlesuits'
|
} from '../../../server/data/honkai3rd/battlesuits'
|
||||||
|
import { useTranslation } from 'next-i18next'
|
||||||
|
|
||||||
interface BattlesuitShowPageProps {
|
interface BattlesuitShowPageProps {
|
||||||
battlesuit: BattlesuitData
|
battlesuit: BattlesuitData
|
||||||
}
|
}
|
||||||
|
|
||||||
const BattlesuitShowPage = ({ battlesuit }: BattlesuitShowPageProps) => {
|
const BattlesuitShowPage = ({ battlesuit }: BattlesuitShowPageProps) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Honkai3rdNavigator />
|
<Honkai3rdNavigator />
|
||||||
@@ -33,8 +35,11 @@ const BattlesuitShowPage = ({ battlesuit }: BattlesuitShowPageProps) => {
|
|||||||
<Box p={3}>
|
<Box p={3}>
|
||||||
<Breadcrumb
|
<Breadcrumb
|
||||||
items={[
|
items={[
|
||||||
{ href: '/honkai3rd', label: 'Honkai 3rd' },
|
{ href: '/honkai3rd', label: t('breadcrumb.honkai-3rd') },
|
||||||
{ href: '/honkai3rd/battlesuits', label: 'Battlesuits' },
|
{
|
||||||
|
href: '/honkai3rd/battlesuits',
|
||||||
|
label: t('breadcrumb.battlesuits'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
href: `/honkai3rd/battlesuits/${battlesuit.id}`,
|
href: `/honkai3rd/battlesuits/${battlesuit.id}`,
|
||||||
label: battlesuit.name,
|
label: battlesuit.name,
|
||||||
@@ -155,6 +160,7 @@ export async function getStaticProps({
|
|||||||
locale,
|
locale,
|
||||||
}: NextPageContext & { params: { battlesuitId: string } }) {
|
}: NextPageContext & { params: { battlesuitId: string } }) {
|
||||||
const battlesuit = getBattlesuitById(params.battlesuitId)
|
const battlesuit = getBattlesuitById(params.battlesuitId)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: { battlesuit, ...(await getI18NProps(locale)) },
|
props: { battlesuit, ...(await getI18NProps(locale)) },
|
||||||
}
|
}
|
||||||
@@ -162,11 +168,13 @@ export async function getStaticProps({
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
return {
|
return {
|
||||||
paths: listBattlesuits().map((battlesuit) => {
|
paths: generateI18NPaths(
|
||||||
return {
|
listBattlesuits().map((battlesuit) => {
|
||||||
params: { battlesuitId: battlesuit.id },
|
return {
|
||||||
}
|
params: { battlesuitId: battlesuit.id },
|
||||||
}),
|
}
|
||||||
|
})
|
||||||
|
),
|
||||||
fallback: false,
|
fallback: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import SecondaryLabel from '../../../components/atoms/SecondaryLabel'
|
|||||||
import Breadcrumb from '../../../components/organisms/Breadcrumb'
|
import Breadcrumb from '../../../components/organisms/Breadcrumb'
|
||||||
import Honkai3rdNavigator from '../../../components/organisms/Honkai3rdNavigator'
|
import Honkai3rdNavigator from '../../../components/organisms/Honkai3rdNavigator'
|
||||||
import { ElfData } from '../../../lib/honkai3rd/elfs'
|
import { ElfData } from '../../../lib/honkai3rd/elfs'
|
||||||
import { getI18NProps } from '../../../lib/i18n'
|
import { generateI18NPaths, getI18NProps } from '../../../lib/i18n'
|
||||||
import { capitalize } from '../../../lib/string'
|
import { capitalize } from '../../../lib/string'
|
||||||
import { getElfById, listElfs } from '../../../server/data/honkai3rd/elfs'
|
import { getElfById, listElfs } from '../../../server/data/honkai3rd/elfs'
|
||||||
|
|
||||||
@@ -116,11 +116,13 @@ export async function getStaticProps({
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
return {
|
return {
|
||||||
paths: listElfs().map((elf) => {
|
paths: generateI18NPaths(
|
||||||
return {
|
listElfs().map((elf) => {
|
||||||
params: { elfId: elf.id },
|
return {
|
||||||
}
|
params: { elfId: elf.id },
|
||||||
}),
|
}
|
||||||
|
})
|
||||||
|
),
|
||||||
fallback: false,
|
fallback: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import SingleStigmataPage, {
|
|||||||
import StigmataSetPage, {
|
import StigmataSetPage, {
|
||||||
StigmataSetProps,
|
StigmataSetProps,
|
||||||
} from '../../../components/pages/StigmataSetPage'
|
} from '../../../components/pages/StigmataSetPage'
|
||||||
import { getI18NProps } from '../../../lib/i18n'
|
import { generateI18NPaths, getI18NProps } from '../../../lib/i18n'
|
||||||
import {
|
import {
|
||||||
listStigmata,
|
listStigmata,
|
||||||
getStigmataById,
|
getStigmataById,
|
||||||
@@ -60,7 +60,7 @@ export async function getStaticProps({
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
return {
|
return {
|
||||||
paths: [
|
paths: generateI18NPaths([
|
||||||
...listStigmata().map((stigmata) => {
|
...listStigmata().map((stigmata) => {
|
||||||
return {
|
return {
|
||||||
params: { stigmataId: stigmata.id },
|
params: { stigmataId: stigmata.id },
|
||||||
@@ -71,7 +71,7 @@ export async function getStaticPaths() {
|
|||||||
params: { stigmataId: `${stigmataSet.id}-set` },
|
params: { stigmataId: `${stigmataSet.id}-set` },
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
],
|
]),
|
||||||
fallback: false,
|
fallback: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import { BattlesuitData } from '../../../lib/honkai3rd/battlesuits'
|
|||||||
import { WeaponData } from '../../../lib/honkai3rd/weapons'
|
import { WeaponData } from '../../../lib/honkai3rd/weapons'
|
||||||
import { SupplyEventData } from '../../../lib/honkai3rd/supplyEvents'
|
import { SupplyEventData } from '../../../lib/honkai3rd/supplyEvents'
|
||||||
import { VersionData } from '../../../lib/honkai3rd/versions'
|
import { VersionData } from '../../../lib/honkai3rd/versions'
|
||||||
import { getI18NProps } from '../../../lib/i18n'
|
import { generateI18NPaths, getI18NProps } from '../../../lib/i18n'
|
||||||
|
|
||||||
interface VersionShowPageProps {
|
interface VersionShowPageProps {
|
||||||
versionData: VersionData
|
versionData: VersionData
|
||||||
@@ -213,13 +213,15 @@ export async function getStaticProps({
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
return {
|
return {
|
||||||
paths: listVersionData().map((versionData) => {
|
paths: generateI18NPaths(
|
||||||
return {
|
listVersionData().map((versionData) => {
|
||||||
params: {
|
return {
|
||||||
versionId: versionData.version.toString(),
|
params: {
|
||||||
},
|
versionId: versionData.version.toString(),
|
||||||
}
|
},
|
||||||
}),
|
}
|
||||||
|
})
|
||||||
|
),
|
||||||
fallback: false,
|
fallback: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import SquareImageBox from '../../../components/atoms/SquareImageBox'
|
|||||||
import Breadcrumb from '../../../components/organisms/Breadcrumb'
|
import Breadcrumb from '../../../components/organisms/Breadcrumb'
|
||||||
import Honkai3rdNavigator from '../../../components/organisms/Honkai3rdNavigator'
|
import Honkai3rdNavigator from '../../../components/organisms/Honkai3rdNavigator'
|
||||||
import { WeaponData } from '../../../lib/honkai3rd/weapons'
|
import { WeaponData } from '../../../lib/honkai3rd/weapons'
|
||||||
import { getI18NProps } from '../../../lib/i18n'
|
import { generateI18NPaths, getI18NProps } from '../../../lib/i18n'
|
||||||
import { capitalize } from '../../../lib/string'
|
import { capitalize } from '../../../lib/string'
|
||||||
import {
|
import {
|
||||||
getWeaponById,
|
getWeaponById,
|
||||||
@@ -94,11 +94,13 @@ export async function getStaticProps({
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
return {
|
return {
|
||||||
paths: listWeapons().map((weapon) => {
|
paths: generateI18NPaths(
|
||||||
return {
|
listWeapons().map((weapon) => {
|
||||||
params: { weaponId: weapon.id },
|
return {
|
||||||
}
|
params: { weaponId: weapon.id },
|
||||||
}),
|
}
|
||||||
|
})
|
||||||
|
),
|
||||||
fallback: false,
|
fallback: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user