Translate weapon list page
This commit is contained in:
@@ -10,7 +10,8 @@
|
|||||||
"breadcrumb": {
|
"breadcrumb": {
|
||||||
"honkai-3rd": "Honkai 3rd",
|
"honkai-3rd": "Honkai 3rd",
|
||||||
"battlesuits": "Battlesuits",
|
"battlesuits": "Battlesuits",
|
||||||
"stigmata": "Stigmata"
|
"stigmata": "Stigmata",
|
||||||
|
"weapons": "Weapons"
|
||||||
},
|
},
|
||||||
"battlesuits-list": {
|
"battlesuits-list": {
|
||||||
"heading": "Battlesuits",
|
"heading": "Battlesuits",
|
||||||
@@ -34,5 +35,9 @@
|
|||||||
"top": "Top",
|
"top": "Top",
|
||||||
"mid": "Mid",
|
"mid": "Mid",
|
||||||
"bot": "Bot"
|
"bot": "Bot"
|
||||||
|
},
|
||||||
|
"weapons-list": {
|
||||||
|
"weapons": "Weapons",
|
||||||
|
"filter-by-category": "Filter by Category"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
"stigmata": "성흔",
|
"stigmata": "성흔",
|
||||||
"top": "(상)",
|
"top": "(상)",
|
||||||
"mid": "(중)",
|
"mid": "(중)",
|
||||||
"bot": "(하)"
|
"bot": "(하)",
|
||||||
|
"weapons": "무기"
|
||||||
},
|
},
|
||||||
"battlesuits-list": {
|
"battlesuits-list": {
|
||||||
"heading": "발키리",
|
"heading": "발키리",
|
||||||
@@ -37,5 +38,9 @@
|
|||||||
"top": "(상)",
|
"top": "(상)",
|
||||||
"mid": "(중)",
|
"mid": "(중)",
|
||||||
"bot": "(하)"
|
"bot": "(하)"
|
||||||
|
},
|
||||||
|
"weapons-list": {
|
||||||
|
"weapons": "무기",
|
||||||
|
"filter-by-category": "카테고리 필터"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
/** @jsxImportSource theme-ui */
|
/** @jsxImportSource theme-ui */
|
||||||
import { Box, Card, Text } from '@theme-ui/components'
|
import { Box, Card, Text } from '@theme-ui/components'
|
||||||
|
import { useRouter } from 'next/router'
|
||||||
import { WeaponData } from '../../lib/honkai3rd/weapons'
|
import { WeaponData } from '../../lib/honkai3rd/weapons'
|
||||||
|
import { translate } from '../../lib/i18n'
|
||||||
import PageLink from '../atoms/PageLink'
|
import PageLink from '../atoms/PageLink'
|
||||||
import SquareImageBox from '../atoms/SquareImageBox'
|
import SquareImageBox from '../atoms/SquareImageBox'
|
||||||
|
|
||||||
interface WeaponCardProps {
|
interface WeaponCardProps {
|
||||||
weapon: Pick<WeaponData, 'id' | 'name' | 'rarity'>
|
weapon: Pick<WeaponData, 'id' | 'name' | 'rarity' | 'krName'>
|
||||||
hidden?: boolean
|
hidden?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const WeaponCard = ({ weapon, hidden }: WeaponCardProps) => {
|
const WeaponCard = ({ weapon, hidden }: WeaponCardProps) => {
|
||||||
|
const { locale } = useRouter()
|
||||||
|
const weaponName = translate(locale, { 'ko-KR': weapon.krName }, weapon.name)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
className={hidden ? 'hidden' : ''}
|
className={hidden ? 'hidden' : ''}
|
||||||
@@ -25,7 +30,7 @@ const WeaponCard = ({ weapon, hidden }: WeaponCardProps) => {
|
|||||||
<PageLink href={`/honkai3rd/weapons/${weapon.id}`}>
|
<PageLink href={`/honkai3rd/weapons/${weapon.id}`}>
|
||||||
<SquareImageBox
|
<SquareImageBox
|
||||||
size={100}
|
size={100}
|
||||||
alt={weapon.name}
|
alt={weaponName}
|
||||||
src={`/assets/honkai3rd/weapons/${weapon.id}.png`}
|
src={`/assets/honkai3rd/weapons/${weapon.id}.png`}
|
||||||
/>
|
/>
|
||||||
<Box
|
<Box
|
||||||
@@ -37,7 +42,7 @@ const WeaponCard = ({ weapon, hidden }: WeaponCardProps) => {
|
|||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Text>{weapon.name}</Text>
|
<Text>{weaponName}</Text>
|
||||||
</Box>
|
</Box>
|
||||||
<Box sx={{ fontSize: 1, textAlign: 'center' }}>
|
<Box sx={{ fontSize: 1, textAlign: 'center' }}>
|
||||||
{'⭐'.repeat(weapon.rarity)}
|
{'⭐'.repeat(weapon.rarity)}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
export interface WeaponSkill {
|
export interface WeaponSkill {
|
||||||
name: string
|
name: string
|
||||||
|
krName?: string
|
||||||
description: string
|
description: string
|
||||||
|
krDescription?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WeaponData {
|
export interface WeaponData {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
|
krName?: string
|
||||||
atk: number
|
atk: number
|
||||||
crt: number
|
crt: number
|
||||||
category:
|
category:
|
||||||
|
|||||||
@@ -11,10 +11,12 @@ import { WeaponData } from '../../../lib/honkai3rd/weapons'
|
|||||||
import WeaponCard from '../../../components/molecules/WeaponCard'
|
import WeaponCard from '../../../components/molecules/WeaponCard'
|
||||||
import { getI18NProps } from '../../../server/i18n'
|
import { getI18NProps } from '../../../server/i18n'
|
||||||
import { NextPageContext } from 'next'
|
import { NextPageContext } from 'next'
|
||||||
|
import { useTranslation } from 'next-i18next'
|
||||||
|
import { translate } from '../../../lib/i18n'
|
||||||
|
|
||||||
type WeaponListItemData = Pick<
|
type WeaponListItemData = Pick<
|
||||||
WeaponData,
|
WeaponData,
|
||||||
'id' | 'name' | 'rarity' | 'category'
|
'id' | 'name' | 'rarity' | 'category' | 'krName'
|
||||||
>
|
>
|
||||||
|
|
||||||
interface WeaponListPageProps {
|
interface WeaponListPageProps {
|
||||||
@@ -22,20 +24,21 @@ interface WeaponListPageProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const weaponFilterOptions = [
|
const weaponFilterOptions = [
|
||||||
{ value: 'all', label: 'All' },
|
{ value: 'all', label: 'All', krLabel: '전체' },
|
||||||
{ value: 'pistol', label: 'Pistols' },
|
{ value: 'pistol', label: 'Pistols', krLabel: '쌍권총' },
|
||||||
{ value: 'katana', label: 'Katanas' },
|
{ value: 'katana', label: 'Katanas', krLabel: '태도' },
|
||||||
{ value: 'cannon', label: 'Cannons' },
|
{ value: 'cannon', label: 'Cannons', krLabel: '대포' },
|
||||||
{ value: 'greatsword', label: 'Greatswords' },
|
{ value: 'greatsword', label: 'Greatswords', krLabel: '대검' },
|
||||||
{ value: 'cross', label: 'Crosses' },
|
{ value: 'cross', label: 'Crosses', krLabel: '십자가' },
|
||||||
{ value: 'gauntlet', label: 'Gauntlets' },
|
{ value: 'gauntlet', label: 'Gauntlets', krLabel: '건틀릿' },
|
||||||
{ value: 'scythe', label: 'Scythes' },
|
{ value: 'scythe', label: 'Scythes', krLabel: '낫' },
|
||||||
{ value: 'lance', label: 'Lances' },
|
{ value: 'lance', label: 'Lances', krLabel: '랜스' },
|
||||||
{ value: 'bow', label: 'Bows' },
|
{ value: 'bow', label: 'Bows', krLabel: '활' },
|
||||||
]
|
]
|
||||||
|
|
||||||
const WeaponListPage = ({ weaponDataList }: WeaponListPageProps) => {
|
const WeaponListPage = ({ weaponDataList }: WeaponListPageProps) => {
|
||||||
const { query } = useRouter()
|
const { query, locale } = useRouter()
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const filter = useMemo(() => {
|
const filter = useMemo(() => {
|
||||||
if (query.filter == null) {
|
if (query.filter == null) {
|
||||||
@@ -64,17 +67,17 @@ const WeaponListPage = ({ weaponDataList }: WeaponListPageProps) => {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Heading as='h1'>Weapons</Heading>
|
<Heading as='h1'>{t('weapons-list.weapons')}</Heading>
|
||||||
<Box>
|
<Box>
|
||||||
<Heading as='h3'>Filter by Category</Heading>
|
<Heading as='h3'>{t('weapons-list.filter-by-category')}</Heading>
|
||||||
<Flex mb={2} sx={{ flexWrap: 'wrap' }}>
|
<Flex mb={2} sx={{ flexWrap: 'wrap' }}>
|
||||||
{weaponFilterOptions.map(({ value, label }) => {
|
{weaponFilterOptions.map(({ value, label, krLabel }) => {
|
||||||
return (
|
return (
|
||||||
<FilterButton
|
<FilterButton
|
||||||
key={value}
|
key={value}
|
||||||
active={value === filter}
|
active={value === filter}
|
||||||
value={value}
|
value={value}
|
||||||
label={label}
|
label={translate(locale, { 'ko-KR': krLabel }, label)}
|
||||||
m={1}
|
m={1}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -100,7 +103,7 @@ export async function getStaticProps({ locale }: NextPageContext) {
|
|||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
weaponDataList: listWeapons().map((weapon) => {
|
weaponDataList: listWeapons().map((weapon) => {
|
||||||
return pick(['name', 'id', 'rarity', 'category'], weapon)
|
return pick(['name', 'id', 'rarity', 'category', 'krName'], weapon)
|
||||||
}),
|
}),
|
||||||
...(await getI18NProps(locale)),
|
...(await getI18NProps(locale)),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { readdirSync, readJsonFileSync } from '../fs'
|
import { readdirSync, readFileSync, readJsonFileSync } from '../fs'
|
||||||
import { compareVersion } from '../../../lib/string'
|
import { compareVersion } from '../../../lib/string'
|
||||||
import { WeaponData } from '../../../lib/honkai3rd/weapons'
|
import { WeaponData } from '../../../lib/honkai3rd/weapons'
|
||||||
|
|
||||||
@@ -8,6 +8,20 @@ const weaponDataList = weaponsFileNameList
|
|||||||
const filePathname = 'honkai3rd/weapons/' + fileName
|
const filePathname = 'honkai3rd/weapons/' + fileName
|
||||||
const data = readJsonFileSync(filePathname) as WeaponData
|
const data = readJsonFileSync(filePathname) as WeaponData
|
||||||
|
|
||||||
|
const krDataFilePath = `honkai3rd/ko-KR/weapons/${data.id}.md`
|
||||||
|
try {
|
||||||
|
const krData = parseWeaponData(readFileSync(krDataFilePath).toString())
|
||||||
|
|
||||||
|
data.krName = krData.name
|
||||||
|
data.skills.forEach((skill, index) => {
|
||||||
|
skill.krName = krData.skills[index].name
|
||||||
|
skill.krDescription = krData.skills[index].description
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
// console.warn('Failed to read', krDataFilePath)
|
||||||
|
// console.warn(error)
|
||||||
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
})
|
})
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
@@ -41,3 +55,22 @@ export function listWeapons() {
|
|||||||
export function getWeaponById(id: string) {
|
export function getWeaponById(id: string) {
|
||||||
return weaponMap.get(id)
|
return weaponMap.get(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseWeaponData(rawData: string) {
|
||||||
|
const [name, ...skillSections] = rawData
|
||||||
|
.split('## ')
|
||||||
|
.map((data) => data.replace(/#+\s/, '').trim())
|
||||||
|
const skills = skillSections.map((skillSection) => {
|
||||||
|
const [skillName, skillDescription] = skillSection.split('\n\n')
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: skillName,
|
||||||
|
description: skillDescription,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
skills,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user