mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
Account for deprecated.json translation info file
This commit is contained in:
@@ -3,6 +3,7 @@ import config from '../Config.js'
|
||||
import { Store } from '../Store.js'
|
||||
import { message } from '../Utils.js'
|
||||
import type { BlockStateRegistry, VersionId } from './Schemas.js'
|
||||
import { checkVersion } from './Schemas.js'
|
||||
|
||||
const CACHE_NAME = 'misode-v2'
|
||||
const CACHE_LATEST_VERSION = 'cached_latest_version'
|
||||
@@ -124,6 +125,9 @@ export async function fetchItemComponents(versionId: VersionId) {
|
||||
console.debug(`[fetchItemComponents] ${versionId}`)
|
||||
const version = config.versions.find(v => v.id === versionId)!
|
||||
const result = new Map<string, Map<string, unknown>>()
|
||||
if (!checkVersion(versionId, '1.20.5')) {
|
||||
return result
|
||||
}
|
||||
try {
|
||||
const data = await cachedFetch<Record<string, Record<string, unknown>>>(`${mcmeta(version, 'summary')}/item_components/data.min.json`)
|
||||
for (const [id, components] of Object.entries(data)) {
|
||||
@@ -267,11 +271,28 @@ async function loadImage(src: string) {
|
||||
}
|
||||
*/
|
||||
|
||||
interface DeprecatedInfo {
|
||||
removed: string[]
|
||||
renamed: Record<string, string>
|
||||
}
|
||||
|
||||
export async function fetchLanguage(versionId: VersionId, lang: string = 'en_us') {
|
||||
const version = config.versions.find(v => v.id === versionId)!
|
||||
await validateCache(version)
|
||||
try {
|
||||
return await cachedFetch<Record<string, string>>(`${mcmeta(version, 'assets')}/assets/minecraft/lang/${lang}.json`)
|
||||
const translations = await cachedFetch<Record<string, string>>(`${mcmeta(version, 'assets')}/assets/minecraft/lang/${lang}.json`)
|
||||
if (checkVersion(versionId, '1.21.2')) {
|
||||
const deprecated = await cachedFetch<DeprecatedInfo>(`${mcmeta(version, 'assets')}/assets/minecraft/lang/deprecated.json`)
|
||||
for (const key of deprecated.removed) {
|
||||
delete translations[key]
|
||||
}
|
||||
for (const [oldKey, newKey] of Object.entries(deprecated.renamed)) {
|
||||
const value = translations[oldKey]
|
||||
delete translations[oldKey]
|
||||
translations[newKey] = value
|
||||
}
|
||||
}
|
||||
return translations
|
||||
} catch (e) {
|
||||
throw new Error(`Error occured while fetching language: ${message(e)}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user