Automatic translation of card names and card information

Hi all,
I'm trying to translate card names and info of all the cards into spanish (or other languages automatically using the info from scryfall).
I have done a python script to automatically translate the card info contained in each .txt card file in cardsfolder. zip with the info retrieved from scryfall. I want to translate the following fields: Name, Types and Oracle. Here is the result of abbot_of_keral_keep.txt:
Could you please help me? It would be nice to have automatically translated cards.
Here is the python script I have done (remove the spaces in the url, 1st post here and I cannot post urls...):
I'm trying to translate card names and info of all the cards into spanish (or other languages automatically using the info from scryfall).
I have done a python script to automatically translate the card info contained in each .txt card file in cardsfolder. zip with the info retrieved from scryfall. I want to translate the following fields: Name, Types and Oracle. Here is the result of abbot_of_keral_keep.txt:
- Code: Select all
Name:Abad de la Fortaleza Keral
ManaCost:1 R
Types:Criatura - Monje humano
PT:2/1
K:Prowess
T:Mode$ ChangesZone | Origin$ Any | Destination$ Battlefield | ValidCard$ Card.Self | Execute$ TrigMill | TriggerDescription$ When CARDNAME enters the battlefield, exile the top card of your library. Until end of turn, you may play that card.
SVar:TrigMill:DB$ Mill | Defined$ You | NumCards$ 1 | Destination$ Exile | RememberMilled$ True | SubAbility$ DBEffect
SVar:DBEffect:DB$ Effect | RememberObjects$ RememberedCard | StaticAbilities$ Play | SubAbility$ DBCleanup | ExileOnMoved$ Exile
SVar:Play:Mode$ Continuous | MayPlay$ True | EffectZone$ Command | Affected$ Card.IsRemembered | AffectedZone$ Exile | Description$ You may play remembered card.
SVar:DBCleanup:DB$ Cleanup | ClearRemembered$ True
SVar:PlayMain1:ALWAYS
SVar:Picture:...
Oracle:Destreza. (Siempre que lances un hechizo que no sea de criatura, esta criatura obtiene +1/+1 hasta el final del turno.)Cuando el Abad de la Fortaleza Keral entre al campo de batalla, exilia la primera carta de tu biblioteca. Hasta el final del turno, puedes jugar esa carta.
Could you please help me? It would be nice to have automatically translated cards.
Here is the python script I have done (remove the spaces in the url, 1st post here and I cannot post urls...):
- Code: Select all
import urllib.request
import re
import os
def sanitize(text):
# remove initial \n and spaces and final \n
text = text[3:]
text = text.strip()
text = text[:-2]
# replace '
text = text.replace("\\xe2\\x80\\x99", "'")
# replace dash
text = text.replace("\\xe2\\x80\\x94", "-")
# replace ""
text = text.replace("\\xe2\\x80\\x9c", "\"")
text = text.replace("\\xe2\\x80\\x9d", "\"")
# replace ·
text = text.replace("\\xe2\\x80\\xa2", "·")
# remove .
text = text.replace("\\xe2\\x80\\xa8", "·")
# replace ñ
text = text.replace("\\xc3\\xb1", "ny")
# replace accute vowels
text = text.replace("\\xc3\\x81", "A")
text = text.replace("\\xc3\\x89", "E")
text = text.replace("\\xc3\\x8d", "I")
text = text.replace("\\xc3\\x93", "O")
text = text.replace("\\xc3\\x9a", "U")
text = text.replace("\\xc3\\xa1", "a")
text = text.replace("\\xc3\\xa9", "e")
text = text.replace("\\xc3\\xad", "i")
text = text.replace("\\xc3\\xb3", "o")
text = text.replace("\\xc3\\xba", "u")
return text
def remove_abbr(result):
result = re.sub("<abbr.*\">", "", result)
result = result.replace("</abbr>", "")
return result
def extract_title(idx):
found = re.findall(r'class="card-text-title" lang="es">(.*?)</h1>',str(respData))
if not found:
return ""
result = found[idx]
# remove mana cost
result = result.replace("<span class=\"card-text-mana-cost\">", "")
result = result.replace("</span>", "")
result = re.sub("{.*}", "", result)
result = result.replace("\\n", "")
result = remove_abbr(result)
result = sanitize(result + "\\n")
return result
def extract_types(idx):
found = re.findall(r'class="card-text-type-line" lang="es">(.*?)</p>',str(respData))
if not found:
return ""
# remove card symbols
result = remove_abbr(found[idx])
if idx==1:
result = result.replace("\\n", "")
result = result + "\\n"
result = sanitize(result)
return result
def extract_oracle(idx):
found = re.findall(r'class="card-text-oracle">(.*?)</div>',str(respData))
if not found:
return ""
if idx < len(found):
result = sanitize(found[idx])
else:
result = sanitize(found[0])
# remove <p>
result = result.replace("<p>", "")
# remove \n
result = result.replace("\\n", "")
# replace </p> to \n
result = result.replace("</p>", "\\n")
# remove italics
result = result.replace("<i>", "")
result = result.replace("</i>", "")
# remove card symbols
result = remove_abbr(result)
# remove trailing \n
result = result[0:-2]
return result
directory = "cards"
for filename in os.listdir(directory):
if filename.endswith(".txt"):
cardname = filename[0:-4]
cardname = cardname.replace("_", "+")
print(cardname)
url = 'https :// scryfall. com/search?as=grid&order=name&q=' + cardname + '+lang:es'
req = urllib.request.Request(url)
resp = urllib.request.urlopen(req)
respData = resp.read()
fi = open("cards/" + filename)
fo = open("cardstranslated/" + filename, "w")
idx = 0
for line in fi:
if "Name" in line[0:4]:
res = extract_title(idx)
if res=="":
res = line[5:-1]
fo.write("Name:" + res + "\n")
elif "Types" in line[0:5]:
res = extract_types(idx)
if res=="":
res = line[6:-1]
fo.write("Types:" + res + "\n")
elif "Oracle" in line[0:6]:
res = extract_oracle(idx)
if res=="":
res = line[7:-1]
fo.write("Oracle:" + res + "\n")
elif "ALTERNATE" in line:
idx = idx + 1
fo.write(line)
else:
fo.write(line)
fi.close()
fo.close()