mirror of
https://github.com/tcgdex/compiler.git
synced 2025-07-28 23:19:50 +00:00
Updated to V2 :D
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
import { getSet, setToSetSimple } from "./setUtil"
|
||||
import { setToSetSimple } from "./setUtil"
|
||||
import { fetchRemoteFile, smartGlob } from "./util"
|
||||
import { Set, SupportedLanguages, Card } from 'db/interfaces'
|
||||
import fetch from 'node-fetch'
|
||||
import { Set, SupportedLanguages, Card, Types } from 'db/interfaces'
|
||||
import { Card as CardSingle, CardResume } from '@tcgdex/sdk/interfaces'
|
||||
import translate, { translateType } from './translationUtil'
|
||||
|
||||
interface ObjectList<T = any> {
|
||||
[key: string]: T
|
||||
@ -53,8 +53,8 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
|
||||
image: image,
|
||||
|
||||
illustrator: card.illustrator,
|
||||
rarity: card.rarity, // translate
|
||||
category: card.category, // translate
|
||||
rarity: translate('rarity', card.rarity, lang) as any,
|
||||
category: translate('category', card.category, lang) as any,
|
||||
variants: {
|
||||
normal: typeof card.variants?.normal === 'boolean' ? card.variants.normal : typeof card.set.variants?.normal === 'boolean' ? card.set.variants.normal : true,
|
||||
reverse: typeof card.variants?.reverse === 'boolean' ? card.variants.reverse : typeof card.set.variants?.reverse === 'boolean' ? card.set.variants.reverse : true,
|
||||
@ -66,38 +66,38 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
|
||||
|
||||
dexId: card.dexId,
|
||||
hp: card.hp,
|
||||
types: card.types, // translate
|
||||
types: card.types?.map((t) => translateType(t, lang)) as Array<Types>,
|
||||
evolveFrom: card.evolveFrom && card.evolveFrom[lang],
|
||||
weight: card.weight,
|
||||
description: card.description ? card.description[lang] as string : undefined,
|
||||
level: card.level,
|
||||
stage: card.stage, // translate
|
||||
suffix: card.suffix, // translate
|
||||
stage: translate('stage', card.stage, lang) as any,
|
||||
suffix: translate('suffix', card.suffix, lang) as any,
|
||||
item: card.item ? {
|
||||
name: card.item.name[lang] as string,
|
||||
effect: card.item.effect[lang] as string
|
||||
} : undefined,
|
||||
|
||||
abilities: card.abilities?.map((el) => ({
|
||||
type: el.type, // translate
|
||||
type: translate('abilityType', el.type, lang) as any,
|
||||
name: el.name[lang] as string,
|
||||
effect: el.effect[lang] as string
|
||||
})),
|
||||
|
||||
attacks: card.attacks?.map((el) => ({
|
||||
cost: el.cost,
|
||||
cost: el.cost?.map((t) => translateType(t, lang)) as Types[],
|
||||
name: el.name[lang] as string,
|
||||
effect: el.effect ? el.effect[lang] : undefined,
|
||||
damage: el.damage
|
||||
})),
|
||||
|
||||
weaknesses: card.weaknesses?.map((el) => ({
|
||||
type: el.type, // translate
|
||||
type: translate('types', el.type, lang) as Types,
|
||||
value: el.value
|
||||
})),
|
||||
|
||||
resistances: card.resistances?.map((el) => ({
|
||||
type: el.type, // translate
|
||||
type: translate('types', el.type, lang) as Types,
|
||||
value: el.value
|
||||
})),
|
||||
|
||||
@ -105,8 +105,8 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
|
||||
|
||||
effect: card.effect ? card.effect[lang] : undefined,
|
||||
|
||||
trainerType: card.trainerType, // translate
|
||||
energyType: card.energyType // translate
|
||||
trainerType: translate('trainerType', card.trainerType, lang) as any,
|
||||
energyType: translate('energyType', card.energyType, lang) as any
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ export async function getCard(serie: string, setName: string, id: string): Promi
|
||||
return (await import(`../db/data/${serie}/${setName}/${id}.js`)).default
|
||||
}
|
||||
|
||||
export async function getCards(set?: Set): Promise<Array<[string, Card]>> {
|
||||
export async function getCards(lang: SupportedLanguages,set?: Set): Promise<Array<[string, Card]>> {
|
||||
const cards = (await smartGlob(`./db/data/${(set && set.serie.name.en) ?? '*'}/${(set && set.name.en) ?? '*'}/*.js`))
|
||||
const list: Array<[string, Card]> = []
|
||||
for (const path of cards) {
|
||||
@ -135,7 +135,7 @@ export async function getCards(set?: Set): Promise<Array<[string, Card]>> {
|
||||
})()
|
||||
console.log(path, id, setName)
|
||||
const c = await getCard(serieName, setName, id)
|
||||
if (!c.name.en) {
|
||||
if (!c.name[lang]) {
|
||||
continue
|
||||
}
|
||||
list.push([id, c])
|
||||
|
@ -1,11 +1,8 @@
|
||||
import { smartGlob } from "./util"
|
||||
import { setToSetSimple, getSets } from "./setUtil"
|
||||
import Logger from "@dzeio/logger"
|
||||
import { Serie, SupportedLanguages } from 'db/interfaces'
|
||||
import { Serie as SerieSingle, SerieResume } from '@tcgdex/sdk/interfaces'
|
||||
|
||||
const logger = new Logger('ExpansionUtils')
|
||||
|
||||
export async function getSeries(): Promise<Array<Serie>> {
|
||||
return Promise.all((await smartGlob('./db/data/*.js'))
|
||||
.map((it) => it.substring(it.lastIndexOf('/') + 1, it.length - 3))
|
||||
|
@ -76,6 +76,6 @@ export async function setToSetSingle(set: Set, lang: SupportedLanguages): Promis
|
||||
// symbol: set.images.symbol,
|
||||
// logo: set.images.logo
|
||||
// },
|
||||
cards: await Promise.all((await getCards(set)).map(([id, card]) => cardToCardSimple(id, card, lang)))
|
||||
cards: await Promise.all((await getCards(lang, set)).map(([id, card]) => cardToCardSimple(id, card, lang)))
|
||||
}
|
||||
}
|
||||
|
101
utils/translationUtil.ts
Normal file
101
utils/translationUtil.ts
Normal file
@ -0,0 +1,101 @@
|
||||
import { SupportedLanguages, Types } from 'db/interfaces'
|
||||
|
||||
type translatable = 'types' | 'rarity' | 'stage' | 'category' | 'suffix' | 'abilityType' | 'trainerType' | 'energyType'
|
||||
|
||||
const translations: Record<string, Record<translatable, Record<string, string>>> = {
|
||||
fr: {
|
||||
types: {
|
||||
'Colorless': 'Incolore',
|
||||
'Darkness': 'Obscurité',
|
||||
'Dragon': 'Dragon',
|
||||
'Fairy': 'Fée',
|
||||
'Fightning': 'Combat',
|
||||
'Fire': 'Feu',
|
||||
'Grass': 'Plante',
|
||||
'Lightning': 'Électrique',
|
||||
'Metal': 'Métal',
|
||||
'Psychic': 'Psy',
|
||||
'Water': 'Eau'
|
||||
},
|
||||
rarity: {
|
||||
'None': 'Rien',
|
||||
'Common': 'Commune',
|
||||
'Uncommon': 'Non Commune',
|
||||
'Rare': 'Rare',
|
||||
'Ultra Rare': 'Ultra Rare',
|
||||
'Secret Rare': 'Magnifique rare'
|
||||
},
|
||||
stage: {
|
||||
"Basic": 'Base',
|
||||
"BREAK": 'TURBO',
|
||||
"LEVEL-UP": 'Niveau Sup',
|
||||
"MEGA": 'MÉGA',
|
||||
"RESTORED": 'RECRÉE',
|
||||
"Stage1": 'Niveau1',
|
||||
"Stage2": 'Biveau2',
|
||||
"VMAX": 'VMAX'
|
||||
},
|
||||
category: {
|
||||
Pokemon: 'Pokémon',
|
||||
Trainer: 'Dresseur',
|
||||
Energy: 'Énergie'
|
||||
},
|
||||
suffix: {
|
||||
'EX': 'EX',
|
||||
'GX': 'GX',
|
||||
'V': 'V',
|
||||
'Legend': 'LÉGENDE',
|
||||
'Prime': 'Prime',
|
||||
'SP': 'SP',
|
||||
'TAG TEAM-GX': 'TAG TEAM-GX',
|
||||
},
|
||||
abilityType: {
|
||||
'Pokemon Power': 'Pouvoir Pokémon',
|
||||
'Poke-BODY': 'Poké-BODY',
|
||||
'Poke-POWER': 'Poké-POWER',
|
||||
'Ability': 'Talent',
|
||||
'Ancient Trait': 'Trait Antique'
|
||||
},
|
||||
trainerType: {
|
||||
'Supporter': 'Supporter',
|
||||
'Item': 'Objet',
|
||||
'Stadium': 'Stade',
|
||||
'Tool': 'Outil',
|
||||
'Ace Spec': 'High-Tech',
|
||||
'Technical Machine': 'Machine Technique',
|
||||
'Goldenred Game Corner': 'Salle de jeu de Doublonville',
|
||||
'Rocket\'s Secret Machine': 'Machine secrète des Rocket'
|
||||
},
|
||||
energyType: {
|
||||
Normal: 'Normal',
|
||||
Special: 'Spécial'
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export default function translate(item: translatable, key: string | undefined, lang: SupportedLanguages) {
|
||||
if (!key) {
|
||||
return key
|
||||
}
|
||||
if (lang === 'en') {
|
||||
return key
|
||||
}
|
||||
const res = translations[lang]?.[item]?.[key]
|
||||
if (!res) {
|
||||
throw new Error(`Could not find translation for ${lang}${item}.${key}`);
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
export function translateType(type: Types, lang: SupportedLanguages) {
|
||||
return translate('types', type, lang)
|
||||
|
||||
}
|
||||
|
||||
export function translateStage(stage: string, lang: SupportedLanguages) {
|
||||
return translate('stage', stage, lang)
|
||||
}
|
||||
|
||||
export function translateRarity(rarity: string, lang: SupportedLanguages) {
|
||||
return translate('rarity', rarity, lang)
|
||||
}
|
Reference in New Issue
Block a user