make the translation file a markdown file (#140)

* make the translation file a markdown file and (blindly) fix the language init script
* Updated formatting of the file to make it easier to read (and look better.)
* Included missing bonuses section
* Also fixed `card_db_dir` to point to the correct directory.

* Added link to Tranlsation instructions

* Updated link to translation.md in README.md
This commit is contained in:
Peter 2017-01-08 10:26:35 -08:00 committed by GitHub
parent 1a1dd9eac8
commit d4e69bc7d3
4 changed files with 607 additions and 518 deletions

View File

@ -8,6 +8,10 @@ This is a script and library to generate card dividers for storing cards for the
Again, to generate tabs go to the ***[Online Generator](http://domtabs.sandflea.org)***. Again, to generate tabs go to the ***[Online Generator](http://domtabs.sandflea.org)***.
## Translations
If you would like to help with translations to new (or updating existing) languages, please see [instructions here] (https://github.com/sumpfork/dominiontabs/blob/master/domdiv/card_db/translation.md).
## Prerequisites ## Prerequisites
#### Python Packages #### Python Packages

View File

@ -0,0 +1,180 @@
# Translation Instructions
## File Format
/card_db/
xx/
bonuses_xx.json
cards_xx.json
sets_xx.json
types_xx.json
where xx is ISO 639-1 standard language code in lower case with under bar '_' replacing dash '-'
Please rename the directory and the files to match the language you are providing.
## Character encoding
The files:
bonuses_xx.json
cards_xx.json
sets_xx.json
types_xx.json
must be encoded in ISO 8859-15, also known as "Latin alphabet no. 9"
This character set is used throughout the Americas, Western Europe, Oceania, and much of Africa.
It is also commonly used in most standard romanizations of East-Asian languages.
If you have a language that is not supported by ISO 8859-15 please contact the developers.
## Anatomy of sets_xx.json
Entries in this file represent Dominion sets/expansions. A typical entry looks like:
"alchemy": {
"set_name": "Alchimia",
"text_icon": "Al"
},
- The set key word (e.g., `alchemy` for the above entry) MUST NOT BE CHANGED. This value is used to identify the translation entry.
- The key word `set_name` MUST NOT BE CHANGED, but the value after the `:` should be changed to the name of the set in the target language.
- The key word `text_icon` MUST NOT BE CHANGED, but the value after the `:` should be a one or two letter identifier to be used by the set if the set graphics are not displayed. This is usually the first letter of the set name in the target language.
- Do not change any punctuation outside of the quotes `"`. For example, brackets `{` or `}`, colons `:`, quotes `"` or commas `,`.
## Anatomy of bonuses_xx.json
Entries in this file represent Dominion bonuses. A typical entry looks like:
"exclude": [
"token",
"Tokens"
],
"include": [
"Coins",
"Coin",
"Cards",
"Card",
"Buys",
"Buy",
"Actions",
"Action",
"<VP>"
]
The items in the `include` list are items that will be marked **bold** (i.e., `<b>..</b>`)
when found in the card text in the following format:
`+# item_from_include_list`
as long as this is not followed by a item from the `exclude` list.
For example in English:
`+2 Buys` will be made bold, but
`+1 Action token` will not, since the key word token follows.
- Just replace the English terms with the terms used in the target language.
- Generally you should include the singular as well as the plural version of the term.
- English versions do not need to be duplicated, since they are used automatically.
- The key words `exclude` and `include` MUST NOT BE CHANGED.
- Do not change any punctuation outside of the quotes `"`. For example, brackets `{` or `}`, colons `:`, quotes `"` or commas `,`.
## Anatomy of types_xx.json
Entries in this file represent Dominion card types. A typical entry looks like:
"Action": "Action in new language",
- The type key word (i.e., the `Action` for the above entry) MUST NOT BE CHANGED. This value is used to identify the translation entry.
- Do not change any punctuation outside of the quotes `"`. For example, brackets `{` or `}`, colons `:`, quotes `"` or commas `,`.
## Anatomy of cards_xx.json
Entries in this file represent Dominion cards, and groups of cards. A typical entry looks like:
"Gold": {
"description": "Worth 3 Coins.",
"extra": "30 cards per game.",
"name": "Gold",
"untranslated" : "description, extra, name"
},
- The card key word (e.g., `Gold` for the above entry) MUST NOT BE CHANGED. This value is used to identify the translation entry.
- The key word `name` MUST NOT BE CHANGED, but the value after the `:` should be changed to the name of the card in the target language.
- The key word `description` MUST NOT BE CHANGED, but the value after the `:` should be changed to the card text in the target language.
- The key word `extra` MUST NOT BE CHANGED, but the value after the `:` should be changed to any extra rules or explanations for the card in the target language. If you purposely want no extra text, enter `""`.
- The key word `untranslated` MUST NOT BE CHANGED, but the value after the `:` should be changed. Removed any key word for which you have provided a translation.
For example:
- if you provided the `name` of the card, and only the `name`, then change to `description, extra`
- if you provided the `name` of the card and it's `description`, but have not translated the `extra`, then change to `extra`
- if you provided all 3 entries, then change to `""`
The "untranslated" entry is used during maintanance of the language files to update any remaining default language entries that might have changed.
## Special Text
These character sequences have special meaning in the "description" and "extra" text:
- `<b>` ... `</b>` for **bold**
- `<i>` ... `</i>` for *italics*
- `<u>` ... `</u>` for underline
- `<tab>` and `<t>` and `\t` to add a tab (4 spaces)
- `<n>` and `\n` for a "hard new line"
- `<br>` and `<br/>` and `<br />` for a "soft new line"
- `<c>` and `<center>` add hard new line and center text until the next hard new line
- `<l>` and `<left>` add hard new line and left align text until the next hard new line
- `<r>` and `<right>` add hard new line and right align text until the next hard new line
- `<j>` and `<justify>` add hard new line and justify align text until the next hard new line
- `<line>` to add a hard new line, a centered dividing line, and a trailing hard new line
Hard new lines (`\n` and `<n>`), will reset the paragraph formatting back to the default.
Soft new lines will insert a new line, but will continue the current formatting.
The `description` will be default to "center" text.
The `extra` will default to "justify" text.
## Special Images
Special character sequences are recognized by the program to substitute graphics in the text. These include:
- `<VP>` and ` VP ` for a Victory Point graphic
- `Potion` for a small Potion graphic
- `# Coin` where # is a number 0 - 13, a question mark `?`, `_`, or the letters `empty` for a small coin graphic with the # on top
- `# Coins` where # is a number 0 - 13, a question mark `?`, `_`, or the letters `empty` for a small coin graphic with the # on top
- `# coin` where # is a number 0 - 13, a question mark `?`, `_`, or the letters `empty` for a small coin graphic with the # on top
- `# coins` where # is a number 0 - 13, a question mark `?`, `_`, or the letters `empty` for a small coin graphic with the # on top
- `# <*COIN*>` where # is a number 0 - 13, will produce a large coin graphic with the # on top
- `# <*VP*>` where # is a number, will produce a large Victory Point graphic with the # before it
- `# <*POTION*>` where # is a number, will produce a large Potion graphic with the # before it
For example:
- the text `1 coin` would produce a graphic of a coin with the number 1 on top.
- the text `empty coin` and `_ coin` would produce a graphic of only a coin.
IMPORTANT: To keep the special images, please do not translate any of the above Special character sequences into the target language.
## Style Guide
- If bonuses_xx.json for the target language is configured correctly, bonuses within the text will automatically be bolded.
In English, it will not bold the text if it is followed by `token` or `Token`. Example:
`Choose one: +3 Cards; or +2 Actions.` will bold `+3 Cards` and `+2 Actions`.
- Bonuses should be listed in the following order:
* `+ Cards`,
* `+ Actions`,
* `+ Buys`,
* `+ Coins`,
* `+ <VP>`
- When possible, bonuses should be listed vertically and centered. Examples:
* `+1 Card<br>+1 Action<br>+1 Buy<br>+1 Coin<br>+2 <VP><n>`
* `+1 Card\n+1 Action\n+1 Buy\n+1 Coin\n+2 <VP>\n`
The `description` field by default is centered. `<br>`, `<n>`, and `\n` will all provide new lines.
- If a Dividers/Tab has more than one card explanation, if space permits, try to mimic a stand alone Dividers/Tab in the overall format. Example from "Settlers - Bustling Village":
`<left><u>Settlers</u>:<n>+1 Card<br>+1 Action<n>Look through your discard pile.
You may reveal a Copper from it and put it into your hand.<n>
<left><u>Bustling Village</u>:<n><center>+1 Card<br>+3 Actions<n>
Look through your discard pile. You may reveal a Settlers from it and put it into your hand.`

View File

@ -1,138 +0,0 @@
# Translation Instructions
## File Format
/card_db/
xx/
bonuses_xx.json
cards_xx.json
sets_xx.json
types_xx.json
where xx is ISO 639-1 standard language code in lower case with under bar '_' replacing dash '-'
Please rename the directory and the files to match the language you are providing.
## Character encoding
The files:
bonuses_xx.json
cards_xx.json
sets_xx.json
types_xx.json
must be encoded in ISO 8859-15, also known as "Latin alphabet no. 9"
This character set is used throughout the Americas, Western Europe, Oceania, and much of Africa.
It is also commonly used in most standard romanizations of East-Asian languages.
If you have a language that is not supported by ISO 8859-15 please contact the developers.
## Anatomy of sets_xx.json
Entries in this file represent Dominion sets/expansions. A typical entry looks like:
"alchemy": {
"set_name": "Alchimia",
"text_icon": "Al"
},
The set key word (e.g., "alchemy" for the above entry) MUST NOT BE CHANGED. This value is used to identify the translation entry.
The key word "set_name" MUST NOT BE CHANGED, but the value after the : should be changed to the name of the set in the target language.
The key word "text_icon" MUST NOT BE CHANGED, but the value after the : should be a one or two letter identifier to be used by the set if the set graphics are not displayed. This is usually the first letter of the set name in the target language.
Do not change any punctuation outside of the quotes '"'. For example, brackets '{' or '}', colons ':', quotes '"' or commas ','.
## Anatomy of bonuses_xx.json
Entries in this file represent Dominion bonuses. The items in the "include" list are items that will be marked bold (i.e., <b>..</b>)
when found in the card text in the following format:
+# item_from_include_list
as long as this is not followed by a item from the "exclude" list.
For example in English:
"+2 Buys" will be made bold, but
"+1 Action token" will not, since the key word token follows.
Just replace the English terms with the terms used in the target language.
Generally you should include the singular as well as the plural version of the term.
English versions do not need to be duplicated, since they are used automatically.
The key words "exclude" and "include" MUST NOT BE CHANGED.
Do not change any punctuation outside of the quotes '"'. For example, brackets '{' or '}', colons ':', quotes '"' or commas ','.
## Anatomy of types_xx.json
Entries in this file represent Dominion card types. A typical entry looks like:
"Action": "Action in new language",
The type key word (i.e., the "Action": for the above entry) MUST NOT BE CHANGED. This value is used to identify the translation entry.
Do not change any punctuation outside of the quotes '"'. For example, brackets '{' or '}', colons ':', quotes '"' or commas ','.
## Anatomy of cards_xx.json
Entries in this file represent Dominion cards, and groups of cards. A typical entry looks like:
"Gold": {
"description": "Worth 3 Coins.",
"extra": "30 cards per game.",
"name": "Gold",
"untranslated" : "description, extra, name"
},
The card key word (e.g., "Gold": for the above entry) MUST NOT BE CHANGED. This value is used to identify the translation entry.
The key word "name" MUST NOT BE CHANGED, but the value after the : should be changed to the name of the card in the target language.
The key word "description" MUST NOT BE CHANGED, but the value after the : should be changed to the card text in the target language.
The key word "extra" MUST NOT BE CHANGED, but the value after the : should be changed to any extra rules or explanations for the card in the target language. If you purposely want no extra text, enter "".
The key word "untranslated" MUST NOT BE CHANGED, but the value after the : should be changed. Removed any key word for which you have provided a translation.
For example:
- if you provided the "name" of the card, and only the "name", then change to "description, extra"
- if you provided the "name" of the card and it's "description", but have not translated the "extra", then change to "extra"
- if you provided all 3 entries, then change to ""
The "untranslated" entry is used during maintanance of the language files to update any remaining default language entries that might have changed.
## Special Text
These character sequences have special meaning in the "description" and "extra" text:
'<b>' ... '</b>' for bold
'<i>' ... '</i>' for italics
'<u>' ... '</u>' for underline
'<tab>' and '<t>' and '\t' to add a tab (4 spaces)
'<n>' and '\n' for a "hard new line"
'<br>' and '<br/>' and '<br />' for a "soft new line"
'<c>' and '<center>' add hard new line and center text until the next hard new line
'<l>' and '<left>' add hard new line and left align text until the next hard new line
'<r>' and '<right>' add hard new line and right align text until the next hard new line
'<j>' and '<justify>' add hard new line and justify align text until the next hard new line
'<line>' to add a hard new line, a centered dividing line, and a trailing hard new line
Hard new lines ('\n' and '<n>'), will reset the paragraph formatting back to the default.
Soft new lines will insert a new line, but will continue the current formatting.
The "description" will be default to "center" text.
The "extra" will default to "justify" text.
## Special Images
Special character sequences are recognized by the program to substitute graphics in the text. These include:
'<VP>' and ' VP ' for a Victory Point graphic
'Potion' for a small Potion graphic
'# Coin' where # is a number 0 - 13, a question mark '?', '_', or the letters 'empty' for a small coin graphic with the # on top
'# Coins' where # is a number 0 - 13, a question mark '?', '_', or the letters 'empty' for a small coin graphic with the # on top
'# coin' where # is a number 0 - 13, a question mark '?', '_', or the letters 'empty' for a small coin graphic with the # on top
'# coins' where # is a number 0 - 13, a question mark '?', '_', or the letters 'empty' for a small coin graphic with the # on top
For example:
- the text '1 coin' would produce a graphic of a coin with the number 1 on top.
- the text 'empty coin' and '_ coin' would produce a graphic of only a coin.
'# <*COIN*>' where # is a number 0 - 13, will produce a large coin graphic with the # on top
'# <*VP*>' where # is a number, will produce a large Victory Point graphic with the # before it
'# <*POTION*>' where # is a number, will produce a large Potion graphic with the # before it
To keep the special images, please do not translate '<VP>', 'Potion', or the 'coin' variations into the target language.
## Style Guide
- If bonuses_xx.json for the target language is configured correctly, bonuses within the text will automatically be bolded.
It will not bold the text if it is followed by 'token' or 'Token'.
Example: "Choose one: +3 Cards; or +2 Actions." will bold '+3 Cards' and '+2 Actions'.
- Bonuses should be listed in the following order:
+Cards, +Actions, +Buys, +Coins, then +<VP>
- When possible, bonuses should be listed vertically and centered.
Examples: "+1 Card<br>+1 Action<br>+1 Buy<br>+1 Coin<br>+2 <VP><n>"
"+1 Card\n+1 Action\n+1 Buy\n+1 Coin\n+2 <VP>\n"
The "description" field by default is centered. '<br>', '<n>', and '\n' will all provide new lines.
- If a Dividers/Tab has more than one card explanation, if space permits, try to mimic a stand alone Dividers/Tab in the overall format.
Example from "Settlers - Bustling Village": "<left><u>Settlers</u>:<n>+1 Card<br>+1 Action<n>Look through your discard pile. You may reveal a Copper from it and put it into your hand.<n><left><u>Bustling Village</u>:<n><center>+1 Card<br>+3 Actions<n>Look through your discard pile. You may reveal a Settlers from it and put it into your hand."

View File

@ -16,10 +16,9 @@ import codecs
import json import json
from shutil import copyfile from shutil import copyfile
LANGUAGE_DEFAULT = 'en_us' # default language, which takes priority LANGUAGE_DEFAULT = 'en_us' # default language, which takes priority
LANGUAGE_XX = 'xx' # language for starting a translation LANGUAGE_XX = 'xx' # language for starting a translation
card_db_dir = os.path.join("..", "card_db") # directory of card data card_db_dir = os.path.join("..", "domdiv", "card_db") # directory of card data
output_dir = os.path.join(".", "card_db") # directory for output data output_dir = os.path.join(".", "card_db") # directory for output data
@ -48,15 +47,19 @@ def json_dict_entry(entry, separator=''):
# Return a nicely formated json dict entry. # Return a nicely formated json dict entry.
# It does not include the enclosing {} and removes trailing white space # 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.dumps(entry, indent=4, ensure_ascii=False, sort_keys=True)
json_data = json_data.strip('{}').rstrip() # Remove outer{} and then trailing whitespace json_data = json_data.strip(
'{}').rstrip() # Remove outer{} and then trailing whitespace
return separator + json_data return separator + json_data
# Multikey sort # Multikey sort
# see: http://stackoverflow.com/questions/1143671/python-sorting-list-of-dictionaries-by-multiple-keys # see: http://stackoverflow.com/questions/1143671/python-sorting-list-of-dictionaries-by-multiple-keys
def multikeysort(items, columns): def multikeysort(items, columns):
from operator import itemgetter from operator import itemgetter
comparers = [((itemgetter(col[1:].strip()), -1) if col.startswith('-') else comparers = [((itemgetter(col[1:].strip()), -1)
(itemgetter(col.strip()), 1)) for col in columns] if col.startswith('-') else (itemgetter(col.strip()), 1))
for col in columns]
def comparer(left, right): def comparer(left, right):
for fn, mult in comparers: for fn, mult in comparers:
result = cmp(fn(left), fn(right)) result = cmp(fn(left), fn(right))
@ -64,8 +67,10 @@ def multikeysort(items, columns):
return mult * result return mult * result
else: else:
return 0 return 0
return sorted(items, cmp=comparer) return sorted(items, cmp=comparer)
########################################################################### ###########################################################################
# Get all the languages, and place the default language first in the list # Get all the languages, and place the default language first in the list
########################################################################### ###########################################################################
@ -78,7 +83,6 @@ print "Languages:"
print languages print languages
print print
########################################################################### ###########################################################################
# Make sure the directories exist to hold the output # Make sure the directories exist to hold the output
########################################################################### ###########################################################################
@ -90,11 +94,10 @@ if not os.path.exists(output_dir):
# each language directory # each language directory
for lang in languages: for lang in languages:
# Make sure the directory is there to hold the file # Make sure the directory is there to hold the file
lang_dir = os.path.join(output_dir,lang) lang_dir = os.path.join(output_dir, lang)
if not os.path.exists(lang_dir): if not os.path.exists(lang_dir):
os.makedirs(lang_dir) os.makedirs(lang_dir)
########################################################################### ###########################################################################
# Get the types_db information # Get the types_db information
# Store in a list in the order found in types[]. Ordered by card_type # Store in a list in the order found in types[]. Ordered by card_type
@ -109,13 +112,16 @@ type_data = get_json_data(os.path.join(card_db_dir, "types_db.json"))
# Sort the cards by cardset_tags, then card_tag # Sort the cards by cardset_tags, then card_tag
sorted_type_data = multikeysort(type_data, ['card_type']) sorted_type_data = multikeysort(type_data, ['card_type'])
with io.open(os.path.join(output_dir, "types_db.json"), 'w', encoding='utf-8') as lang_out: with io.open(
os.path.join(output_dir, "types_db.json"), 'w',
encoding='utf-8') as lang_out:
lang_out.write(unicode("[")) # Start of list lang_out.write(unicode("[")) # Start of list
sep = "" sep = ""
for type in sorted_type_data: for type in sorted_type_data:
# Collect all the individual types # Collect all the individual types
type_parts = list(set(type['card_type']) | set(type_parts)) type_parts = list(set(type['card_type']) | set(type_parts))
lang_out.write(sep + json.dumps(type, indent=4, ensure_ascii=False, sort_keys=True)) lang_out.write(sep + json.dumps(
type, indent=4, ensure_ascii=False, sort_keys=True))
sep = "," sep = ","
lang_out.write(unicode("\n]\n")) # End of List lang_out.write(unicode("\n]\n")) # End of List
@ -124,7 +130,6 @@ print "Unique Types:"
print type_parts print type_parts
print print
########################################################################### ###########################################################################
# Fix up all the xx/types_xx.json files # Fix up all the xx/types_xx.json files
# Place entries in alphabetical order # Place entries in alphabetical order
@ -142,7 +147,9 @@ for lang in languages:
else: else:
lang_type_data = {} lang_type_data = {}
with io.open( os.path.join(output_dir, lang, lang_file), 'w',encoding='utf-8') as lang_out: with io.open(
os.path.join(output_dir, lang, lang_file), 'w',
encoding='utf-8') as lang_out:
lang_out.write(unicode("{")) # Start of types lang_out.write(unicode("{")) # Start of types
sep = "" sep = ""
used = [] used = []
@ -151,17 +158,21 @@ for lang in languages:
if type not in lang_type_data: if type not in lang_type_data:
if lang == LANGUAGE_DEFAULT: if lang == LANGUAGE_DEFAULT:
lang_type_data[type] = type lang_type_data[type] = type
lang_type_default = lang_type_data
else: else:
lang_type_data[type] = lang_type_default[type] lang_type_data[type] = lang_type_default[type]
lang_out.write(json_dict_entry({type:lang_type_data[type]}, sep)) lang_out.write(json_dict_entry({type: lang_type_data[type]}, sep))
used.append(type) used.append(type)
sep = "," sep = ","
# Now keep any unused values just in case needed in the future # Now keep any unused values just in case needed in the future
for key in lang_type_data: for key in lang_type_data:
if key not in used: if key not in used:
lang_out.write(json_dict_entry({key:lang_type_data[key]}, sep)) lang_out.write(
json_dict_entry({
key: lang_type_data[key]
}, sep))
sep = "," sep = ","
lang_out.write(unicode("\n}\n")) # End of Types lang_out.write(unicode("\n}\n")) # End of Types
@ -169,7 +180,6 @@ for lang in languages:
if lang == LANGUAGE_DEFAULT: if lang == LANGUAGE_DEFAULT:
lang_type_default = lang_type_data # Keep for later languages lang_type_default = lang_type_data # Keep for later languages
########################################################################### ###########################################################################
# Get the cards_db information # Get the cards_db information
# Store in a list in the order found in cards[]. Ordered as follows: # Store in a list in the order found in cards[]. Ordered as follows:
@ -193,7 +203,9 @@ for card in card_data:
# Sort the cards by cardset_tags, then card_tag # Sort the cards by cardset_tags, then card_tag
sorted_card_data = multikeysort(card_data, ['cardset_tags', 'card_tag']) sorted_card_data = multikeysort(card_data, ['cardset_tags', 'card_tag'])
with io.open(os.path.join(output_dir, "cards_db.json"), 'w', encoding='utf-8') as lang_out: with io.open(
os.path.join(output_dir, "cards_db.json"), 'w',
encoding='utf-8') as lang_out:
lang_out.write(unicode("[")) # Start of list lang_out.write(unicode("[")) # Start of list
sep = "" sep = ""
for card in sorted_card_data: for card in sorted_card_data:
@ -202,7 +214,8 @@ with io.open(os.path.join(output_dir, "cards_db.json"), 'w', encoding='utf-8') a
if 'group_tag' in card: if 'group_tag' in card:
if card['group_tag'] not in groups: if card['group_tag'] not in groups:
groups.append(card['group_tag']) groups.append(card['group_tag'])
lang_out.write(sep + json.dumps(card, indent=4, ensure_ascii=False, sort_keys=True)) lang_out.write(sep + json.dumps(
card, indent=4, ensure_ascii=False, sort_keys=True))
sep = "," sep = ","
lang_out.write(unicode("\n]\n")) # End of List lang_out.write(unicode("\n]\n")) # End of List
@ -233,7 +246,9 @@ for lang in languages:
lang_data = {} lang_data = {}
# Process the file # Process the file
with io.open(os.path.join(output_dir, lang, lang_file), 'w', encoding='utf-8') as lang_out: with io.open(
os.path.join(output_dir, lang, lang_file), 'w',
encoding='utf-8') as lang_out:
lang_out.write(unicode("{")) # Start of set lang_out.write(unicode("{")) # Start of set
sep = "" sep = ""
fields = [u"description", u"extra", u"name"] fields = [u"description", u"extra", u"name"]
@ -248,11 +263,13 @@ for lang in languages:
lang_data[card]["name"] = card lang_data[card]["name"] = card
lang_data[card]["description"] = "" lang_data[card]["description"] = ""
lang_data[card]["untranslated"] = ', '.join(fields) lang_data[card]["untranslated"] = ', '.join(fields)
lang_default = lang_data
else: else:
# All other languages should get the default languages' text # All other languages should get the default languages' text
lang_data[card]["extra"] = lang_default[card]["extra"] lang_data[card]["extra"] = lang_default[card]["extra"]
lang_data[card]["name"] = lang_default[card]["name"] lang_data[card]["name"] = lang_default[card]["name"]
lang_data[card]["description"] = lang_default[card]["description"] lang_data[card]["description"] = lang_default[card][
"description"]
lang_data[card]["untranslated"] = ', '.join(fields) lang_data[card]["untranslated"] = ', '.join(fields)
else: else:
# Card exists, figure out what needs updating (don't update default language) # Card exists, figure out what needs updating (don't update default language)
@ -266,34 +283,37 @@ for lang in languages:
# If a field remains untranslated, then replace with the default languages copy # If a field remains untranslated, then replace with the default languages copy
for field in fields: for field in fields:
if field in lang_data[card]['untranslated']: if field in lang_data[card]['untranslated']:
lang_data[card][field] = lang_default[card][field] lang_data[card][field] = lang_default[
card][field]
else: else:
# Need to create the 'untranslated' field and update based upon existing fields # Need to create the 'untranslated' field and update based upon existing fields
untranslated = [] untranslated = []
for field in fields: for field in fields:
if field not in lang_data[card]: if field not in lang_data[card]:
lang_data[card][field] = lang_default[card][field] lang_data[card][field] = lang_default[card][
field]
untranslated.append(field) untranslated.append(field)
if untranslated: if untranslated:
# only add if something is still needing translation # only add if something is still needing translation
lang_data[card]["untranslated"] = ', '.join(untranslated) lang_data[card]["untranslated"] = ', '.join(
untranslated)
lang_out.write(json_dict_entry({card:lang_data[card]}, sep)) lang_out.write(json_dict_entry({card: lang_data[card]}, sep))
lang_data[card]['used'] = True lang_data[card]['used'] = True
sep = "," sep = ","
# Now keep any unused values just in case needed in the future # Now keep any unused values just in case needed in the future
for key in lang_data: for key in lang_data:
if 'used' not in lang_data[key]: if 'used' not in lang_data[key]:
lang_data[key]["untranslated"] = "Note: This card is currently not used." lang_data[key][
lang_out.write(json_dict_entry({key:lang_data[key]}, sep)) "untranslated"] = "Note: This card is currently not used."
lang_out.write(json_dict_entry({key: lang_data[key]}, sep))
sep = "," sep = ","
lang_out.write(unicode("\n}\n")) # End of Set lang_out.write(unicode("\n}\n")) # End of Set
if lang == LANGUAGE_DEFAULT: if lang == LANGUAGE_DEFAULT:
lang_default = lang_data # Keep for later languages lang_default = lang_data # Keep for later languages
########################################################################### ###########################################################################
# Fix up the sets_db.json file # Fix up the sets_db.json file
# Place entries in alphabetical order # Place entries in alphabetical order
@ -301,12 +321,14 @@ for lang in languages:
lang_file = "sets_db.json" lang_file = "sets_db.json"
set_data = get_json_data(os.path.join(card_db_dir, lang_file)) set_data = get_json_data(os.path.join(card_db_dir, lang_file))
with io.open( os.path.join(output_dir, lang_file), 'w',encoding='utf-8') as lang_out: with io.open(
os.path.join(output_dir, lang_file), 'w',
encoding='utf-8') as lang_out:
lang_out.write(unicode("{")) # Start of set lang_out.write(unicode("{")) # Start of set
sep = "" sep = ""
sets = [] sets = []
for set in sorted(set_data): for set in sorted(set_data):
lang_out.write(json_dict_entry({set:set_data[set]}, sep)) lang_out.write(json_dict_entry({set: set_data[set]}, sep))
sep = "," sep = ","
if set not in sets: if set not in sets:
sets.append(set) sets.append(set)
@ -317,7 +339,6 @@ print "Sets:"
print sets print sets
print print
########################################################################### ###########################################################################
# Fix up all the xx/sets_xx.json files # Fix up all the xx/sets_xx.json files
# Place entries in alphabetical order # Place entries in alphabetical order
@ -335,7 +356,9 @@ for lang in languages:
else: else:
lang_set_data = {} lang_set_data = {}
with io.open( os.path.join(output_dir, lang, lang_file), 'w',encoding='utf-8') as lang_out: with io.open(
os.path.join(output_dir, lang, lang_file), 'w',
encoding='utf-8') as lang_out:
lang_out.write(unicode("{")) # Start of set lang_out.write(unicode("{")) # Start of set
sep = "" sep = ""
@ -344,23 +367,28 @@ for lang in languages:
lang_set_data[set] = {} lang_set_data[set] = {}
if lang == LANGUAGE_DEFAULT: if lang == LANGUAGE_DEFAULT:
lang_set_data[set]["set_name"] = set.title() lang_set_data[set]["set_name"] = set.title()
lang_set_data[set]["text_icon"] = set_data[set]["text_icon"] lang_set_data[set]["text_icon"] = set_data[set][
"text_icon"]
if 'short_name' in set_data[set]: if 'short_name' in set_data[set]:
lang_set_data[set]["short_name"] = set_data[set]["short_name"] lang_set_data[set]["short_name"] = set_data[set][
"short_name"]
else: else:
lang_set_data[set]["set_name"] = lang_default[set]["set_name"] lang_set_data[set]["set_name"] = lang_default[set][
lang_set_data[set]["text_icon"] = lang_default[set]["text_icon"] "set_name"]
lang_set_data[set]["text_icon"] = lang_default[set][
"text_icon"]
if 'short_name' in lang_default[set]: if 'short_name' in lang_default[set]:
lang_set_data[set]["short_name"] = lang_default[set]["short_name"] lang_set_data[set]["short_name"] = lang_default[set][
"short_name"]
lang_out.write(json_dict_entry({set:lang_set_data[set]}, sep)) lang_out.write(json_dict_entry({set: lang_set_data[set]}, sep))
lang_set_data[set]['used'] = True lang_set_data[set]['used'] = True
sep = "," sep = ","
# Now keep any unused values just in case needed in the future # Now keep any unused values just in case needed in the future
for key in lang_set_data: for key in lang_set_data:
if 'used' not in lang_set_data[key]: if 'used' not in lang_set_data[key]:
lang_out.write(json_dict_entry({key:lang_set_data[key]}, sep)) lang_out.write(json_dict_entry({key: lang_set_data[key]}, sep))
sep = "," sep = ","
lang_out.write(unicode("\n}\n")) # End of Set lang_out.write(unicode("\n}\n")) # End of Set
@ -368,13 +396,28 @@ for lang in languages:
if lang == LANGUAGE_DEFAULT: if lang == LANGUAGE_DEFAULT:
lang_default = lang_set_data # Keep for later languages lang_default = lang_set_data # Keep for later languages
###########################################################################
# bonuses_xx files
###########################################################################
for lang in languages:
# Special case for xx. Reseed from default language
fromLanguage = lang
if lang == LANGUAGE_XX:
fromLanguage = LANGUAGE_DEFAULT
copyfile(
os.path.join(card_db_dir, fromLanguage, "bonuses_" + fromLanguage + ".json"),
os.path.join(output_dir, lang, "bonuses_" + lang + ".json"))
########################################################################### ###########################################################################
# translation.txt # translation.txt
########################################################################### ###########################################################################
copyfile(os.path.join(card_db_dir, "translation.txt" ), copyfile(
os.path.join(output_dir, "translation.txt" )) os.path.join(card_db_dir, "translation.md"),
os.path.join(output_dir, "translation.md"))
# Since xx is the starting point for new translations, # Since xx is the starting point for new translations,
# make sure xx has the latest copy of translation.txt # make sure xx has the latest copy of translation.md
copyfile(os.path.join(card_db_dir, "translation.txt" ), copyfile(
os.path.join(output_dir, LANGUAGE_XX, "translation.txt" )) os.path.join(card_db_dir, "translation.md"),
os.path.join(output_dir, LANGUAGE_XX, "translation.md"))