Language Support in Tooltips (#468)

* Add lang parameter to TextCompoennt

* Add 'mclang' key

* Add clearing old language cache when changed language

* Fetch language in background

* Remove auto-fetching mc language

* wrap mclang with a state

* update contributos

* Move 'mclang' to config.json

* Cleanup code to get mclang key and fix caching

---------

Co-authored-by: Misode <misoloo64@gmail.com>
This commit is contained in:
efekos
2024-02-24 23:55:41 +03:00
committed by GitHub
parent 7a7c7d675e
commit 231ecfe9c2
6 changed files with 51 additions and 29 deletions

View File

@@ -1,10 +1,11 @@
import type { ItemStack } from 'deepslate/core'
import { AttributeModifierOperation, Enchantment, Identifier, MobEffectInstance, Potion } from 'deepslate/core'
import { NbtList, NbtType } from 'deepslate/nbt'
import { message } from '../Utils.js'
import { useLocale } from '../contexts/Locale.jsx'
import { useVersion } from '../contexts/Version.jsx'
import { useAsync } from '../hooks/useAsync.js'
import { getLanguage, getTranslation } from '../services/Resources.js'
import { message } from '../Utils.js'
import { TextComponent } from './TextComponent.jsx'
interface Props {
@@ -13,8 +14,9 @@ interface Props {
}
export function ItemTooltip({ item, advanced }: Props) {
const { version } = useVersion()
const { lang } = useLocale()
const { value: language } = useAsync(() => getLanguage(version), [version])
const { value: language } = useAsync(() => getLanguage(version, lang), [version, lang])
const isPotion = item.is('potion') || item.is('splash_potion') || item.is('lingering_potion')
let displayName = item.tag.getCompound('display').getString('Name')

View File

@@ -1,4 +1,5 @@
import { useMemo } from 'preact/hooks'
import { useLocale } from '../contexts/Locale.jsx'
import { useVersion } from '../contexts/Version.jsx'
import { useAsync } from '../hooks/useAsync.js'
import { getLanguage, replaceTranslation } from '../services/Resources.js'
@@ -25,6 +26,7 @@ interface Props {
}
export function TextComponent({ component, base = { color: 'white' }, shadow = true }: Props) {
const { version } = useVersion()
const { lang } = useLocale()
const state = JSON.stringify(component)
const parts = useMemo(() => {
@@ -33,7 +35,7 @@ export function TextComponent({ component, base = { color: 'white' }, shadow = t
return parts
}, [state, base])
const { value: language } = useAsync(() => getLanguage(version), [version])
const { value: language } = useAsync(() => getLanguage(version, lang), [version, lang])
return <div class="text-component">
{shadow && <div>