mirror of
https://github.com/tcgdex/compiler.git
synced 2025-04-22 10:42:09 +00:00
32 lines
993 B
TypeScript
32 lines
993 B
TypeScript
import { SupportedLanguages } from 'db/interfaces'
|
|
import es from '../db/meta/translations/es.json'
|
|
import it from '../db/meta/translations/it.json'
|
|
import pt from '../db/meta/translations/pt.json'
|
|
import de from '../db/meta/translations/de.json'
|
|
import fr from '../db/meta/translations/fr.json'
|
|
|
|
type translatable = 'types' | 'rarity' | 'stage' | 'category' | 'suffix' | 'abilityType' | 'trainerType' | 'energyType'
|
|
|
|
const translations: Record<string, Record<translatable, Record<string, string>>> = {
|
|
es,
|
|
fr,
|
|
it,
|
|
pt,
|
|
de
|
|
}
|
|
|
|
export default function translate(item: translatable, key: string | undefined, lang: SupportedLanguages): string | undefined {
|
|
if (!key) {
|
|
return key
|
|
}
|
|
// Temporary trenslations are in english while they are being worked on
|
|
if (lang === 'en' || !Object.keys(translations).includes(lang)) {
|
|
return key
|
|
}
|
|
const res = translations[lang]?.[item]?.[key]
|
|
if (!res) {
|
|
throw new Error(`Could not find translation for ${lang}${item}.${key}`)
|
|
}
|
|
return res
|
|
}
|