Skip to content

Commit

Permalink
fix: showcase etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Nov 18, 2024
1 parent f929364 commit 2b85cde
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/components/virtual/SelectorItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ import { useTranslation } from 'react-i18next'
/** @param {FullProps} props */
export function SelectorItem({
id,
category,
filter,
setFilter,
onClick,
hasAll,
easyMode,
}) {
const { t } = useTranslateById({ alt: true, newLine: true })
const { t } = useTranslateById({
alt: true,
newLine: true,
quest: category === 'pokestops',
})
const title = t(id)
const url = useMemory((s) => s.Icons.getIconById(id))

Expand Down
1 change: 1 addition & 0 deletions src/components/virtual/StandardItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function StandardItem({ id, category, ...props }) {
<SelectorItem
{...props}
id={id}
category={category}
filter={filter}
setFilter={setFilter}
hasAll={hasAll}
Expand Down
2 changes: 1 addition & 1 deletion src/features/drawer/components/SelectorList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function SelectorList({ category, subCategory, label, height = 400 }) {
subCategory ? capitalize(subCategory) : ''
}QuickSelect`
const { available } = useGetAvailable(category)
const { t: tId } = useTranslateById()
const { t: tId } = useTranslateById({ quest: subCategory === 'pokemon' })
const { t } = useTranslation()
const allFilters = useMemory((s) => s.filters[category]?.filter)

Expand Down
1 change: 1 addition & 0 deletions src/features/webhooks/tiles/WebhookItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function WebhookItem({ id, category, ...props }) {
<SelectorItem
{...props}
id={id}
category={category}
filter={filter}
setFilter={setFilter}
onClick={() =>
Expand Down
20 changes: 15 additions & 5 deletions src/hooks/useTranslateById.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-fallthrough */
// @ts-check
import { useMemo } from 'react'
import { useEffect, useMemo, useRef } from 'react'
import { useTranslation } from 'react-i18next'

/**
* @typedef {{ plural?: boolean, amount?: boolean, alt?: boolean, newLine?: boolean }} CustomTOptions
* @typedef {{ plural?: boolean, amount?: boolean, alt?: boolean, newLine?: boolean, quest?: boolean }} CustomTOptions
* @typedef {(id: string, options?: CustomTOptions) => string} CustomT
*/

Expand All @@ -14,11 +14,16 @@ import { useTranslation } from 'react-i18next'
*/
export function useTranslateById(options = {}) {
const i18n = useTranslation()
const formsToIgnore = useRef(new Set([i18n.t('form_0'), i18n.t('form_45')]))

useEffect(() => {
formsToIgnore.current = new Set([i18n.t('form_0'), i18n.t('form_45')])
}, [i18n.i18n.language])

return useMemo(
() => ({
language: i18n.i18n.language,
t: (id, { plural, amount, alt, newLine } = options) => {
t: (id, { plural, amount, alt, newLine, quest } = options) => {
if (typeof id !== 'string') {
return ''
}
Expand Down Expand Up @@ -105,13 +110,18 @@ export function useTranslateById(options = {}) {
case 'f':
// showcase mons
id = id.slice(1)
quest = false
default: {
// pokemon
const [pokemon, form] = id.split('-', 2)
const pokemonName = i18n.t(`poke_${pokemon}`)
return form === undefined
const possibleForm = i18n.t(`form_${form}`)
const hideForm = quest
? form === undefined
: formsToIgnore.current.has(possibleForm)
return hideForm
? pokemonName
: `${pokemonName}${newLine ? '\n' : ' '}(${i18n.t(`form_${form}`)})`
: `${pokemonName}${newLine ? '\n' : ' '}(${possibleForm})`
}
}
},
Expand Down

0 comments on commit 2b85cde

Please sign in to comment.