Skip to content

Commit d71f67b

Browse files
committed
Only throw LocalizationErrors in debug mode.
Make sure that we can struggle on in the face of any non-fatal errors and recover things like the summary stats and gameplay graphs.
1 parent d71a73f commit d71f67b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sc2reader/resources.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,11 @@ def load_translations(self):
797797
for uid, (sheet, item) in self.id_map.items():
798798
if sheet < len(sheets) and item in sheets[sheet]:
799799
translation[uid] = sheets[sheet][item]
800-
else:
800+
elif self.opt.debug:
801801
msg = "No {0} translation for sheet {1}, item {2}"
802802
raise SC2ReaderLocalizationError(msg.format(self.opt.lang,sheet,item))
803+
else:
804+
translation[uid] = "Unknown"
803805

804806
self.lang_sheets[lang] = sheets
805807
self.translations[lang] = translation
@@ -865,7 +867,7 @@ def use_property(prop, player=None):
865867

866868
translation = self.translations[self.opt.lang]
867869
for uid, prop in properties.items():
868-
name = self.translations[self.opt.lang][uid]
870+
name = translation.get(uid, "Unknown")
869871
if prop.is_lobby:
870872
if use_property(prop):
871873
value = prop.values[settings[uid]][0]
@@ -891,7 +893,7 @@ def load_player_stats(self):
891893
stats_items.append(self.parts[4][0][0])
892894

893895
for item in stats_items:
894-
stat_name = translation[item[0][1]]
896+
stat_name = translation.get(item[0][1],"Unknown")
895897
for index, value in enumerate(item[1]):
896898
if value:
897899
self.player_stats[index][stat_name] = value[0][0]
@@ -929,6 +931,9 @@ def load_player_builds(self):
929931
BuildEntry = namedtuple('BuildEntry',['supply','total_supply','time','order','build_index'])
930932
for build_item in build_items:
931933
translation_key = build_item[0][1]
934+
# Here instead of recording unknown entries we just skip them because
935+
# it seems that unknown entries actually don't belong in the build order
936+
# We should revisit this decision in the future.
932937
if translation_key in translation:
933938
order_name = translation[translation_key]
934939
for pindex, commands in enumerate(build_item[1]):

0 commit comments

Comments
 (0)