From 70fb1e63b9a3ed700570d1209b14815cf947c741 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 4 Mar 2022 19:05:17 -0800 Subject: [PATCH] Add translations for hovercards --- components/CharacterHovercard/index.tsx | 15 ++++++++----- components/SummonHovercard/index.tsx | 16 +++++++++----- components/WeaponHovercard/index.tsx | 29 +++++++++++++++---------- public/locales/en/common.json | 3 ++- public/locales/ja/common.json | 3 ++- 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/components/CharacterHovercard/index.tsx b/components/CharacterHovercard/index.tsx index 73dada07..9ae4c78d 100644 --- a/components/CharacterHovercard/index.tsx +++ b/components/CharacterHovercard/index.tsx @@ -1,11 +1,12 @@ import React from 'react' +import { useRouter } from 'next/router' +import { useTranslation } from 'next-i18next' + import * as HoverCard from '@radix-ui/react-hover-card' import WeaponLabelIcon from '~components/WeaponLabelIcon' import UncapIndicator from '~components/UncapIndicator' -import { axData } from '~utils/axData' - import './index.scss' interface Props { @@ -21,6 +22,10 @@ interface KeyNames { } const CharacterHovercard = (props: Props) => { + const router = useRouter() + const { t } = useTranslation('common') + const locale = (router.locale && ['en', 'ja'].includes(router.locale)) ? router.locale : 'en' + const Element = ['null', 'wind', 'fire', 'water', 'earth', 'dark', 'light'] const Proficiency = ['none', 'sword', 'dagger', 'axe', 'spear', 'bow', 'staff', 'fist', 'harp', 'gun', 'katana'] @@ -56,8 +61,8 @@ const CharacterHovercard = (props: Props) => {
-

{ props.gridCharacter.object.name.en }

- {props.gridCharacter.object.name.en} +

{ props.gridCharacter.object.name[locale] }

+ {props.gridCharacter.object.name[locale]}
@@ -76,7 +81,7 @@ const CharacterHovercard = (props: Props) => {
- View more on gbf.wiki + {t('buttons.wiki')} diff --git a/components/SummonHovercard/index.tsx b/components/SummonHovercard/index.tsx index 5db30251..f989da7e 100644 --- a/components/SummonHovercard/index.tsx +++ b/components/SummonHovercard/index.tsx @@ -1,11 +1,12 @@ import React from 'react' +import { useRouter } from 'next/router' +import { useTranslation } from 'next-i18next' + import * as HoverCard from '@radix-ui/react-hover-card' import WeaponLabelIcon from '~components/WeaponLabelIcon' import UncapIndicator from '~components/UncapIndicator' -import { axData } from '~utils/axData' - import './index.scss' interface Props { @@ -21,8 +22,11 @@ interface KeyNames { } const SummonHovercard = (props: Props) => { + const router = useRouter() + const { t } = useTranslation('common') + const locale = (router.locale && ['en', 'ja'].includes(router.locale)) ? router.locale : 'en' + const Element = ['null', 'wind', 'fire', 'water', 'earth', 'dark', 'light'] - const Proficiency = ['none', 'sword', 'dagger', 'axe', 'spear', 'bow', 'staff', 'fist', 'harp', 'gun', 'katana'] const tintElement = Element[props.gridSummon.object.element] const wikiUrl = `https://gbf.wiki/${props.gridSummon.object.name.en.replaceAll(' ', '_')}` @@ -57,8 +61,8 @@ const SummonHovercard = (props: Props) => {
-

{ props.gridSummon.object.name.en }

- {props.gridSummon.object.name.en} +

{ props.gridSummon.object.name[locale] }

+ {props.gridSummon.object.name[locale]}
@@ -72,7 +76,7 @@ const SummonHovercard = (props: Props) => { />
- View more on gbf.wiki + {t('buttons.wiki')} diff --git a/components/WeaponHovercard/index.tsx b/components/WeaponHovercard/index.tsx index 70e5500e..5c497c5f 100644 --- a/components/WeaponHovercard/index.tsx +++ b/components/WeaponHovercard/index.tsx @@ -1,4 +1,7 @@ import React from 'react' +import { useRouter } from 'next/router' +import { useTranslation } from 'next-i18next' + import * as HoverCard from '@radix-ui/react-hover-card' import WeaponLabelIcon from '~components/WeaponLabelIcon' @@ -16,29 +19,33 @@ interface Props { interface KeyNames { [key: string]: { en: string, - jp: string + ja: string } } const WeaponHovercard = (props: Props) => { + const router = useRouter() + const { t } = useTranslation('common') + const locale = (router.locale && ['en', 'ja'].includes(router.locale)) ? router.locale : 'en' + const Element = ['null', 'wind', 'fire', 'water', 'earth', 'dark', 'light'] const Proficiency = ['none', 'sword', 'dagger', 'axe', 'spear', 'bow', 'staff', 'fist', 'harp', 'gun', 'katana'] const WeaponKeyNames: KeyNames = { '2': { en: 'Pendulum', - jp: '' + ja: 'ペンデュラム' }, '3': { en: 'Teluma', - jp: '' + ja: 'テルマ' }, '17': { en: 'Gauph Key', - jp: '' + ja: 'ガフスキー' }, '22': { en: 'Emblem', - jp: '' + ja: 'エンブレム' } } @@ -61,7 +68,7 @@ const WeaponHovercard = (props: Props) => { const simpleAxSkill = props.gridWeapon.ax[0] const axSkill = primaryAxSkills.find(skill => skill.id == simpleAxSkill.modifier) - return `${axSkill?.name.en} +${simpleAxSkill.strength}${ (axSkill?.suffix) ? axSkill.suffix : '' }` + return `${axSkill?.name[locale]} +${simpleAxSkill.strength}${ (axSkill?.suffix) ? axSkill.suffix : '' }` } return '' @@ -78,7 +85,7 @@ const WeaponHovercard = (props: Props) => { if (primaryAxSkill && primaryAxSkill.secondary) { const secondaryAxSkill = primaryAxSkill.secondary.find(skill => skill.id == secondarySimpleAxSkill.modifier) - return `${secondaryAxSkill?.name.en} +${secondarySimpleAxSkill.strength}${ (secondaryAxSkill?.suffix) ? secondaryAxSkill.suffix : '' }` + return `${secondaryAxSkill?.name[locale]} +${secondarySimpleAxSkill.strength}${ (secondaryAxSkill?.suffix) ? secondaryAxSkill.suffix : '' }` } } @@ -104,7 +111,7 @@ const WeaponHovercard = (props: Props) => { Array.from(Array(props.gridWeapon.weapon_keys.length)).map((x, i) => { return (
- {props.gridWeapon.weapon_keys![i].name.en} + {props.gridWeapon.weapon_keys![i].name[locale]}
) }) : '' } @@ -137,8 +144,8 @@ const WeaponHovercard = (props: Props) => {
-

{ props.gridWeapon.object.name.en }

- {props.gridWeapon.object.name.en} +

{ props.gridWeapon.object.name[locale] }

+ {props.gridWeapon.object.name[locale]}
@@ -158,7 +165,7 @@ const WeaponHovercard = (props: Props) => { { (props.gridWeapon.object.ax > 0 && props.gridWeapon.ax && props.gridWeapon.ax[0].modifier && props.gridWeapon.ax[0].strength ) ? axSection : '' } { (props.gridWeapon.weapon_keys && props.gridWeapon.weapon_keys.length > 0) ? keysSection : '' } - View more on gbf.wiki + {t('buttons.wiki')} diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 31556df2..8376ce6a 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -5,7 +5,8 @@ "edit_info": "Edit info", "hide_info": "Hide info", "menu": "Menu", - "new": "New" + "new": "New", + "wiki": "View more on gbf.wiki" }, "modals": { "about": { diff --git a/public/locales/ja/common.json b/public/locales/ja/common.json index e0ce247d..47f2d4a8 100644 --- a/public/locales/ja/common.json +++ b/public/locales/ja/common.json @@ -5,7 +5,8 @@ "show_info": "詳細を編集", "hide_info": "詳細を非表示", "menu": "メニュー", - "new": "作成" + "new": "作成", + "wiki": "gbf.wikiで詳しく見る" }, "modals": { "about": {