CZ language files (#152)
* Added add_language.py Tool to make it easier to add a new language from the csv file * Add language files for cz
This commit is contained in:
parent
37fb05f9a6
commit
3578804882
16
domdiv/card_db/cz/bonuses_cz.json
Normal file
16
domdiv/card_db/cz/bonuses_cz.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"exclude": [
|
||||
"token",
|
||||
"Tokens"
|
||||
],
|
||||
"include": [
|
||||
"Coins",
|
||||
"Coin",
|
||||
"Cards",
|
||||
"Card",
|
||||
"Buys",
|
||||
"Buy",
|
||||
"Actions",
|
||||
"Action"
|
||||
]
|
||||
}
|
||||
2312
domdiv/card_db/cz/cards_cz.json
Normal file
2312
domdiv/card_db/cz/cards_cz.json
Normal file
File diff suppressed because it is too large
Load Diff
96
domdiv/card_db/cz/sets_cz.json
Normal file
96
domdiv/card_db/cz/sets_cz.json
Normal file
@ -0,0 +1,96 @@
|
||||
{
|
||||
"adventures": {
|
||||
"set_name": "Adventures",
|
||||
"text_icon": "Ad"
|
||||
},
|
||||
"adventures extras": {
|
||||
"set_name": "Adventures Extras",
|
||||
"text_icon": "Ad"
|
||||
},
|
||||
"alchemy": {
|
||||
"set_name": "Alchemy",
|
||||
"text_icon": "A"
|
||||
},
|
||||
"base": {
|
||||
"set_name": "Base",
|
||||
"text_icon": "B"
|
||||
},
|
||||
"cornucopia": {
|
||||
"set_name": "Cornucopia",
|
||||
"text_icon": "C"
|
||||
},
|
||||
"cornucopia extras": {
|
||||
"set_name": "Cornucopia Extras",
|
||||
"text_icon": "C"
|
||||
},
|
||||
"dark ages": {
|
||||
"set_name": "Dark Ages",
|
||||
"text_icon": "DA"
|
||||
},
|
||||
"dark ages extras": {
|
||||
"set_name": "Dark Ages Extras",
|
||||
"text_icon": "DA"
|
||||
},
|
||||
"dominion1stEdition": {
|
||||
"set_name": "Dominion 1st Edition",
|
||||
"short_name": "Dominion",
|
||||
"text_icon": "D1"
|
||||
},
|
||||
"dominion2ndEdition": {
|
||||
"set_name": "Dominion 2nd Edition",
|
||||
"short_name": "Dominion",
|
||||
"text_icon": "D2"
|
||||
},
|
||||
"dominion2ndEditionUpgrade": {
|
||||
"set_name": "Dominion 2nd Edition Upgrade",
|
||||
"short_name": "Dominion",
|
||||
"text_icon": "D2"
|
||||
},
|
||||
"empires": {
|
||||
"set_name": "Empires",
|
||||
"text_icon": "E"
|
||||
},
|
||||
"empires extras": {
|
||||
"set_name": "Empires Extras",
|
||||
"text_icon": "E"
|
||||
},
|
||||
"extras": {
|
||||
"set_name": "Extras",
|
||||
"text_icon": "X"
|
||||
},
|
||||
"guilds": {
|
||||
"set_name": "Guilds",
|
||||
"text_icon": "G"
|
||||
},
|
||||
"hinterlands": {
|
||||
"set_name": "Hinterlands",
|
||||
"text_icon": "H"
|
||||
},
|
||||
"intrigue1stEdition": {
|
||||
"set_name": "Intrigue 1st Edition",
|
||||
"short_name": "Intrigue",
|
||||
"text_icon": "I1"
|
||||
},
|
||||
"intrigue2ndEdition": {
|
||||
"set_name": "Intrigue 2nd Edition",
|
||||
"short_name": "Intrigue",
|
||||
"text_icon": "I2"
|
||||
},
|
||||
"intrigue2ndEditionUpgrade": {
|
||||
"set_name": "Intrigue 2nd Edition Upgrade",
|
||||
"short_name": "Intrigue",
|
||||
"text_icon": "I2"
|
||||
},
|
||||
"promo": {
|
||||
"set_name": "Promo",
|
||||
"text_icon": "Po"
|
||||
},
|
||||
"prosperity": {
|
||||
"set_name": "Prosperity",
|
||||
"text_icon": "Py"
|
||||
},
|
||||
"seaside": {
|
||||
"set_name": "Seaside",
|
||||
"text_icon": "S"
|
||||
}
|
||||
}
|
||||
26
domdiv/card_db/cz/types_cz.json
Normal file
26
domdiv/card_db/cz/types_cz.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"Action": "Action",
|
||||
"Attack": "Attack",
|
||||
"Blank": "Blank",
|
||||
"Castle": "Castle",
|
||||
"Curse": "Curse",
|
||||
"Duration": "Duration",
|
||||
"Event": "Event",
|
||||
"Events": "Events",
|
||||
"Expansion": "Expansion",
|
||||
"Gathering": "Gathering",
|
||||
"Landmark": "Landmark",
|
||||
"Landmarks": "Landmarks",
|
||||
"Looter": "Looter",
|
||||
"Prize": "Prize",
|
||||
"Prizes": "Prizes",
|
||||
"Reaction": "Reaction",
|
||||
"Reserve": "Reserve",
|
||||
"Ruins": "Ruins",
|
||||
"Shelter": "Shelter",
|
||||
"Shelters": "Shelters",
|
||||
"Trash": "Trash",
|
||||
"Traveller": "Traveller",
|
||||
"Treasure": "Treasure",
|
||||
"Victory": "Victory"
|
||||
}
|
||||
110
tools/add_language.py
Normal file
110
tools/add_language.py
Normal file
@ -0,0 +1,110 @@
|
||||
import os
|
||||
import codecs
|
||||
import json
|
||||
import sys
|
||||
import io
|
||||
import csv
|
||||
from shutil import copyfile
|
||||
|
||||
LANGUAGE_DEFAULT = 'en_us' # default language, which takes priority
|
||||
LANGUAGE_XX = 'xx' # language for starting a translation
|
||||
|
||||
card_db_dir = os.path.join("..", "domdiv", "card_db") # directory of card data
|
||||
output_dir = os.path.join(".", "card_db") # directory for output data
|
||||
crossReference = "./CrossReference"
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
LANGUAGE_NEW = sys.argv[1].strip().lower()
|
||||
else:
|
||||
print "Usage: ", sys.argv[0], " xx"
|
||||
print "where xx is the two letter language abreviation."
|
||||
sys.exit()
|
||||
|
||||
def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
|
||||
csv_reader = csv.reader(utf8_data, dialect=dialect, **kwargs)
|
||||
for row in csv_reader:
|
||||
yield [unicode(cell, 'iso-8859-15') for cell in row]
|
||||
#yield [unicode(cell, 'iso-8859-1') for cell in row]
|
||||
#yield [cell.decode('iso-8859-1').encode('utf8') for cell in row]
|
||||
|
||||
def get_json_data(json_file_path):
|
||||
# Read in the json from the specified file
|
||||
with codecs.open(json_file_path, 'r', 'utf-8') as json_file:
|
||||
data = json.load(json_file)
|
||||
assert data, "Could not load json at: '%r' " % json_file_path
|
||||
return data
|
||||
|
||||
|
||||
def json_dict_entry(entry, separator=''):
|
||||
# Return a nicely formated json dict entry.
|
||||
# It does not include the enclosing {} and removes trailing white space
|
||||
json_data = json.dumps(entry, indent=4, ensure_ascii=False, sort_keys=True)
|
||||
json_data = json_data.strip(
|
||||
'{}').rstrip() # Remove outer{} and then trailing whitespace
|
||||
return separator + json_data
|
||||
|
||||
def find_index(items, find):
|
||||
if find in items:
|
||||
return items.index(find)
|
||||
else:
|
||||
return None
|
||||
|
||||
reader = unicode_csv_reader(open(crossReference + '.csv'))
|
||||
cards = list(reader)
|
||||
headers = cards[0]
|
||||
|
||||
if not os.path.exists(output_dir):
|
||||
os.makedirs(output_dir)
|
||||
|
||||
lang_dir = os.path.join(output_dir, LANGUAGE_NEW)
|
||||
if not os.path.exists(lang_dir):
|
||||
os.makedirs(lang_dir)
|
||||
|
||||
for f in ['bonuses_', 'cards_', 'sets_', 'types_']:
|
||||
copyfile(
|
||||
os.path.join(card_db_dir, LANGUAGE_XX, f + LANGUAGE_XX + '.json'),
|
||||
os.path.join(output_dir, LANGUAGE_NEW, f + LANGUAGE_NEW + '.json'))
|
||||
|
||||
|
||||
lang_index = find_index(headers, LANGUAGE_NEW)
|
||||
card_index = find_index(headers, 'card_tag')
|
||||
|
||||
if lang_index is None or card_index is None:
|
||||
print "Cound not find new language '",LANGUAGE_NEW, "' in the CrossReference file"
|
||||
print "Files copied, but no name changes were made."
|
||||
sys.exit()
|
||||
|
||||
# Get the new names for those in the CrossReference
|
||||
cardlist = {}
|
||||
for row in cards:
|
||||
if row[lang_index]:
|
||||
cardlist[row[card_index]] = row[lang_index]
|
||||
|
||||
# Update the names based upon names in the cross reference file
|
||||
fname = os.path.join(card_db_dir, LANGUAGE_XX, "cards_" + LANGUAGE_XX + ".json")
|
||||
if os.path.isfile(fname):
|
||||
lang_data = get_json_data(fname)
|
||||
else:
|
||||
print "ERROR: Failed to open :", fname
|
||||
sys.exit()
|
||||
|
||||
if cardlist:
|
||||
with io.open(
|
||||
os.path.join(output_dir, LANGUAGE_NEW, "cards_" + LANGUAGE_NEW + ".json"), 'w',
|
||||
encoding='utf-8') as lang_out:
|
||||
|
||||
lang_out.write(unicode("{")) # Start of set
|
||||
sep = ""
|
||||
|
||||
|
||||
for card in lang_data:
|
||||
# print card, lang_data[card]
|
||||
data = lang_data[card]
|
||||
if card in cardlist:
|
||||
# Have a new name, so update name
|
||||
data['name'] = cardlist[card]
|
||||
fields = [u"description", u"extra"] # but no u"name"
|
||||
data['untranslated'] = ', '.join(fields)
|
||||
lang_out.write(json_dict_entry({card: data}, sep))
|
||||
sep = ","
|
||||
lang_out.write(unicode("\n}\n")) # End of Set
|
||||
Loading…
x
Reference in New Issue
Block a user