Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
René Kooi
committed
Oct 27, 2014
1 parent
9555147
commit 91cbcf3
Showing
3 changed files
with
73 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# HD Edition uses short language codes. | ||
# For consistency with AoK:TC's PE-file-extracted codes, they are mapped to these longer codes | ||
|
||
short_to_long_codes_map = { | ||
'br': 'pt_BR', | ||
'cn': 'zh_CN', | ||
'de': 'de_DE', | ||
'en': 'en_US', | ||
'es': 'es_ES', | ||
'fr': 'fr_FR', | ||
'it': 'it_IT', | ||
'ja': 'ja_JP', | ||
'ko': 'ko_KR', | ||
'nl': 'nl_NL', | ||
'ru': 'ru_RU' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from collections import defaultdict | ||
from . import util | ||
from .hardcoded.langcodes_hd import short_to_long_codes_map | ||
from .util import dbg | ||
|
||
class HDLanguageFile: | ||
|
||
def __init__(self, fname, langcode): | ||
self.fname = fname | ||
self.lang = short_to_long_codes_map[langcode] if langcode in short_to_long_codes_map else langcode | ||
fname = util.file_get_path(fname) | ||
|
||
dbg("HD Language file [%s]" % (fname), 1) | ||
self.data = open(fname, mode='r', encoding='iso-8859-1').read() | ||
self.strings = self.extract_strings() | ||
|
||
def extract_strings(self): | ||
result = defaultdict(lambda: {}) | ||
for i in self.data.split('\n'): | ||
i = i.strip() | ||
#comments & empty lines | ||
if i.startswith('//') or len(i) == 0: | ||
continue | ||
num, string = i.split(None, 1) | ||
#strings that were added in the HD edition release have UPPERCASE_STRINGS | ||
#as names, instead of the numeric ID stuff in AoK:TC | ||
#we only need the AoK:TC strings, and skip the rest | ||
if num.isdigit(): | ||
result[self.lang][num] = string | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters