Add Japanese localization and fix split card view

This commit is contained in:
Alumi
2021-02-19 04:05:22 +00:00
committed by Michael Kamensky
parent cbc72ef2e5
commit 92d9bebc58
10 changed files with 23457 additions and 35 deletions

View File

@@ -0,0 +1,175 @@
#!/usr/bin/env python3
import os
import urllib.request
sets = [
'4ED', 'CHR', 'ICE', 'ALL', 'MIR', 'VIS', '5ED', 'POR', 'WTH', 'TMP',
'STH', 'EXO', 'P02', 'USG', 'ULG', '6ED', 'PTK', 'UDS', 'MMQ', 'NEM',
'PCY', 'INV', 'PLS', '7ED', 'APC', 'ODY', 'TOR', 'JUD', 'ONS', 'LGN',
'SCG', '8ED', 'MRD', 'DST', '5DN', 'CHK', 'BOK', 'SOK', '9ED', 'RAV',
'GPT', 'DIS', 'CSP', 'TSP', 'PLC', 'FUT', '10E', 'LRW', 'MOR', 'SHM',
'EVE', 'ALA', 'CFX', 'ARB', 'M10', 'HOP', 'ZEN', 'WWK', 'ROE', 'M11',
'SOM', 'MBS', 'NPH', 'CMD', 'M12', 'ISD', 'DKA', 'AVR', 'PC2', 'M13',
'RTR', 'GTC', 'DGM', 'M14', 'THS', 'C13', 'BNG', 'JOU', 'CNS', 'M15',
'KTK', 'C14', 'FRF', 'DTK', 'ORI', 'BFZ', 'C15', 'OGW', 'SOI', 'EMA',
'EMN', 'CN2', 'KLD', 'C16', 'AER', 'AKH', 'HOU', 'C17', 'XLN', 'IMA',
'RIX', 'A25', 'DOM', 'BBD', 'M19', 'C18', 'GRN', 'UMA', 'RNA', 'WAR',
'MH1', 'M20', 'C19', 'ELD', 'THB', 'IKO', 'C20', 'M21', 'JMP', '2XM',
'ZNR', 'ZNC', 'CMR', 'KHM', 'KHC',
]
costmap = [
('(白)', '{W}'),
('(青)', '{U}'),
('(黒)', '{B}'),
('(赤)', '{R}'),
('(緑)', '{G}'),
('(◇)', '{C}'),
('()', '{0}'),
('()', '{1}'),
('()', '{2}'),
('()', '{3}'),
('()', '{4}'),
('()', '{5}'),
('()', '{6}'),
('()', '{7}'),
('()', '{8}'),
('()', '{9}'),
('()', '{10}'),
('()', '{11}'),
('()', '{12}'),
('()', '{13}'),
('()', '{14}'),
('()', '{15}'),
('()', '{16}'),
('()', '{X}'),
('(白/青)', '{W/U}'),
('(白/黒)', '{W/B}'),
('(青/黒)', '{U/B}'),
('(青/赤)', '{U/R}'),
('(黒/赤)', '{B/R}'),
('(黒/緑)', '{B/G}'),
('(赤/緑)', '{R/G}'),
('(赤/白)', '{R/W}'),
('(緑/白)', '{G/W}'),
('(緑/青)', '{G/U}'),
('(/白)', '{2/W}'),
('(/青)', '{2/U}'),
('(/黒)', '{2/B}'),
('(/赤)', '{2/R}'),
('(/緑)', '{2/G}'),
('(白/Φ)', '{W/P}'),
('(青/Φ)', '{U/P}'),
('(黒/Φ)', '{B/P}'),
('(赤/Φ)', '{R/P}'),
('(緑/Φ)', '{G/P}'),
('(氷)', '{S}'),
('()', '{T}'),
('()', '{Q}'),
('()', '{E}'),
]
def remove_engtype(text):
text = text.replace('(Urzas)', 'ウルザの')
while text.rfind('(') != -1:
left_index = text.rindex('(')
right_index = text.rindex(')')
if text[left_index + 1:right_index].isascii():
text = text[:left_index] + text[right_index + 1:]
else:
break
return text
def replace_cost(text):
for cm in costmap:
text = text.replace(cm[0], cm[1])
return text
def writecard(cardfile, cardname, jap_name, jap_type, jap_text):
if jap_name.rfind('') != -1:
jap_name = jap_name[:jap_name.rindex('')]
elif len(jap_name) == 0:
jap_name = cardname
jap_type = jap_type.replace(' --- ', '')
jap_type = remove_engtype(jap_type)
jap_text = replace_cost(jap_text)
jap_text = remove_engtype(jap_text)
jap_text = jap_text.replace('\n', '\\n')
cardfile.write(cardname + '|' + jap_name + '|' + jap_type + '|' + jap_text + '\n')
def processcards(cardfile, cur_set):
datafilename = f'ja-JP/{cur_set}.txt'
if not os.path.exists(datafilename):
if cur_set == 'CFX':
cur_set = 'CON'
card_data = urllib.request.urlopen(f'http://whisper.wisdom-guild.net/cardlist/{cur_set}.txt').read().decode('shift_jis')
with open(datafilename, 'w', encoding='utf8') as datafile:
datafile.write(card_data)
with open(datafilename, 'r', encoding='utf8') as datafile:
cardname = ''
jap_name = ''
jap_type = ''
jap_text = ''
text_mode = False
for line in datafile:
if line.startswith(' 英語名:'):
if text_mode is True:
text_mode = False
jap_text = jap_text.rstrip('\n')
writecard(cardfile, cardname, jap_name, jap_type, jap_text)
jap_name = ''
jap_type = ''
jap_text = ''
cardname = line[len(' 英語名:'):].rstrip('\n')
cardname = cardname.replace('AEther', 'Aether')
elif line.startswith('日本語名:'):
jap_name = line[len('日本語名:'):].rstrip('\n')
elif line.startswith(' タイプ:'):
jap_type = line[len(' タイプ:'):].rstrip('\n')
text_mode = True
elif line.startswith('イラスト:'):
text_mode = False
jap_text = jap_text.rstrip('\n')
writecard(cardfile, cardname, jap_name, jap_type, jap_text)
cardname = ''
jap_name = ''
jap_type = ''
jap_text = ''
elif line.startswith(' '):
continue
elif text_mode and not line.isspace():
jap_text += line
def cleanfile(filename, extension1, extension2):
names_seen = set()
outfile = open(filename + extension2, 'w', encoding='utf8')
with open(filename + extension1, 'r', encoding='utf8') as r:
for line in sorted(r):
name = line.split('|')[0]
if name not in names_seen:
outfile.write(line)
names_seen.add(name)
outfile.close()
os.remove(filename + extension1)
def main():
if not os.path.exists('ja-JP'):
os.makedirs('ja-JP')
with open('cardnames-ja-JP.tmp', 'w', encoding='utf8') as cardfile:
for cur_set in sets:
print (f'Processing {cur_set} ...')
processcards(cardfile, cur_set)
# Sort file and remove duplicates
cleanfile('cardnames-ja-JP', '.tmp', ".txt")
if __name__ == '__main__':
main()