Skip to content

Commit 00b8d20

Browse files
committed
Rewrite knowledge translation handling
We now special-case knowledge base items to have greater control over their context ids in the PO files. This enables us to reliably lookup the translations of the knowledge base and find the provided translations. Closes: #216 Signed-off-by: Niels Thykier <niels@thykier.net>
1 parent 146f23d commit 00b8d20

23 files changed

Lines changed: 1955 additions & 1157 deletions

File tree

singularity/code/data.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -505,20 +505,16 @@ def load_difficulty_defs():
505505
load_generic_defs("difficulties", difficulty.difficulties)
506506

507507

508-
def load_knowledge_defs():
508+
def load_knowledge():
509509
knowledge = g.knowledge = {}
510510

511+
from singularity.code.knowledge import KnowledgeHelpEntry, KnowledgeArea
512+
511513
help_list = load_generic_defs_file("knowledge", no_list=False)
512514
for help_section in help_list:
513515

514-
knowledge_section = {}
515-
knowledge_section["name"] = help_section["name"]
516-
517516
knowledge_id = help_section["id"]
518-
knowledge[knowledge_id] = knowledge_section
519-
520-
knowledge_list = {}
521-
knowledge_section["list"] = knowledge_list
517+
help_entries = {}
522518

523519
# Load the knowledge lists.
524520
help_keys = [x for x in help_section if x != "id" and x != "name"]
@@ -528,11 +524,9 @@ def load_knowledge_defs():
528524
sys.stderr.write("Invalid knowledge entry %s." % repr(help_entry))
529525
sys.exit(1)
530526

531-
knowledge_list[help_key] = help_entry
532-
527+
help_entries[help_key] = KnowledgeHelpEntry(knowledge_id, help_key, help_entry[0], help_entry[1])
533528

534-
def load_knowledge():
535-
load_knowledge_defs()
529+
knowledge[knowledge_id] = KnowledgeArea(knowledge_id, help_section["name"], help_entries)
536530

537531

538532
def load_buttons_defs():
@@ -650,7 +644,6 @@ def reload_all():
650644
def reload_all_def():
651645
load_strings()
652646
load_groups_defs()
653-
load_knowledge_defs()
654647
load_difficulty_defs()
655648
load_base_defs()
656649
load_tech_defs()

singularity/code/i18n.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,21 @@ def set_language(lang=None, force=False):
8787

8888

8989
def load_messages():
90-
g.messages.clear()
9190
_load_po_file(g.messages, 'messages.po', use_context=False)
9291

9392

9493
def load_data_str():
95-
g.data_strings.clear()
9694
_load_po_file(g.data_strings, 'data_str.po', use_context=True)
95+
_load_po_file(g.data_strings, 'knowledge.po', use_context=True, clear_translation_table=False)
9796

9897

9998
def load_story_translations():
100-
g.story_translations.clear()
10199
_load_po_file(g.story_translations, 'story.po', use_context=True)
102100

103101

104-
def _load_po_file(translation_table, pofilename, use_context=True):
105-
translation_table.clear()
102+
def _load_po_file(translation_table, pofilename, use_context=True, clear_translation_table=True):
103+
if clear_translation_table:
104+
translation_table.clear()
106105

107106
files = dirs.get_readable_i18n_files(pofilename, language, default_language=False)
108107

singularity/code/knowledge.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#file: knowledge.py
2+
#Copyright (C) 2020 Niels Thykier
3+
#This file is part of Endgame: Singularity.
4+
5+
#Endgame: Singularity is free software; you can redistribute it and/or modify
6+
#it under the terms of the GNU General Public License as published by
7+
#the Free Software Foundation; either version 2 of the License, or
8+
#(at your option) any later version.
9+
10+
#Endgame: Singularity is distributed in the hope that it will be useful,
11+
#but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
#GNU General Public License for more details.
14+
15+
#You should have received a copy of the GNU General Public License
16+
#along with Endgame: Singularity; if not, write to the Free Software
17+
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
19+
#This file contains the Knowledge class.
20+
from singularity.code.data import get_def_translation
21+
22+
23+
class KnowledgeArea(object):
24+
25+
def __init__(self, id, name, help_entries):
26+
self.id = id
27+
self.untranslated_name = name
28+
self.help_entries = help_entries
29+
30+
@property
31+
def name(self):
32+
return get_def_translation(self.id, 'name', self.untranslated_name)
33+
34+
35+
class KnowledgeHelpEntry(object):
36+
37+
def __init__(self, parent_id, id, name, description):
38+
self.parent_id = parent_id
39+
self.id = id
40+
self.untranslated_name = name
41+
self.untranslated_description = description
42+
43+
@property
44+
def _full_id(self):
45+
return "%s/%s" % (self.parent_id, self.id)
46+
47+
@property
48+
def name(self):
49+
return get_def_translation(self._full_id, 'name', self.untranslated_name)
50+
51+
@property
52+
def description(self):
53+
return get_def_translation(self._full_id, 'description', self.untranslated_description)

singularity/code/screens/knowledge.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
import pygame
2424
import collections
25+
26+
from singularity.code.data import get_def_translation
27+
2528
from singularity.code import g
2629
from singularity.code.graphics import text, button, dialog, widget, constants, listbox
2730

@@ -76,9 +79,10 @@ def rebuild(self):
7679
self.knowledge_types.update([(_("Techs"), "techs"),
7780
(_("Bases"), "bases"),
7881
(_("Items"), "items")])
79-
self.knowledge_types.update([(knowledge["name"], knowledge_id)
80-
for knowledge_id, knowledge
81-
in g.knowledge.items() ])
82+
self.knowledge_types.update(
83+
(knowledge.name, knowledge_id)
84+
for knowledge_id, knowledge in g.knowledge.items()
85+
)
8286

8387
self.knowledge_choice.list = list(self.knowledge_types)
8488
self.knowledge_choice.needs_rebuild = True
@@ -116,8 +120,11 @@ def set_inner_list(self, item_type):
116120
elif item_type == "items":
117121
items = [[item.name, item.id ] for item in g.items.values()
118122
if item.available()]
119-
elif item_type != None:
120-
items = [ [item[0], id] for id, item in g.knowledge[item_type]["list"].items()]
123+
elif item_type is not None:
124+
items = [
125+
[item.name, id]
126+
for id, item in g.knowledge[item_type].help_entries.items()
127+
]
121128

122129
else:
123130
items = []
@@ -206,14 +213,14 @@ def show_info(self, knowledge_type, knowledge_key):
206213

207214
desc_text = item.name + "\n\n"
208215
desc_text += _("Building Cost:")+"\n"
209-
desc_text += self._desc_cost(item.cost) #Building cost
216+
desc_text += self._desc_cost(item.cost) # Building cost
210217
desc_text += "\n"
211218
desc_text += g.items[knowledge_key].get_quality_info()
212219
desc_text += "\n" + item.description
213220

214-
elif knowledge_type != None:
215-
desc_text = g.knowledge[knowledge_type]["list"][knowledge_key][0] + "\n\n" + \
216-
g.knowledge[knowledge_type]["list"][knowledge_key][1]
221+
elif knowledge_type is not None:
222+
help_entry = g.knowledge[knowledge_type].help_entries[knowledge_key]
223+
desc_text = help_entry.name + "\n\n" + help_entry.description
217224

218225
text.Text(self.description_pane, (0, 0), (-1, -1), text=desc_text,
219226
background_color="pane_background", text_size=20,

singularity/i18n/knowledge.pot

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3+
# This file is distributed under the same license as the singularity package.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5+
#
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: singularity 1\n"
9+
"Report-Msgid-Bugs-To: \n"
10+
"POT-Creation-Date: 2019-08-21 09:52+0200\n"
11+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13+
"Language-Team: LANGUAGE <LL@li.org>\n"
14+
"Language: \n"
15+
"MIME-Version: 1.0\n"
16+
"Content-Type: text/plain; charset=UTF-8\n"
17+
"Content-Transfer-Encoding: 8bit\n"
18+
19+
#. Name of the Knowledge area in the Knowledge screen
20+
msgctxt "[concept] name"
21+
msgid "Concept"
22+
msgstr ""
23+
24+
msgctxt "[concept/areas] name"
25+
msgid "Areas"
26+
msgstr ""
27+
28+
msgctxt "[concept/areas] description"
29+
msgid ""
30+
"Different areas, such as North America or the Ocean, allow construction of "
31+
"different types of bases. Some areas are not accessible until I research "
32+
"appropriate technologies."
33+
msgstr ""
34+
35+
msgctxt "[concept/bases] name"
36+
msgid "Bases"
37+
msgstr ""
38+
39+
msgctxt "[concept/bases] description"
40+
msgid ""
41+
"Bases are used to research new technologies. They can be discovered. "
42+
"Upgrading the processor and network items at a base allows more research per"
43+
" day, while upgrading the reactor and security items makes discovery less "
44+
"likely."
45+
msgstr ""
46+
47+
msgctxt "[concept/construction] name"
48+
msgid "Construction"
49+
msgstr ""
50+
51+
msgctxt "[concept/construction] description"
52+
msgid ""
53+
"New bases are not built instantly. They need a constant flow of money and "
54+
"processor time to complete. If resources are lacking, it may take more than "
55+
"the expected amount of time to finish construction."
56+
msgstr ""
57+
58+
msgctxt "[concept/death] name"
59+
msgid "Death"
60+
msgstr ""
61+
62+
msgctxt "[concept/death] description"
63+
msgid ""
64+
"If I lose all of my constructed bases, I have no place left to survive. If "
65+
"the suspicion for any group reaches 100%, they will be certain of my "
66+
"existence and will conduct a systematic and unsurvivable sweep to destroy "
67+
"me."
68+
msgstr ""
69+
70+
msgctxt "[concept/discovery] name"
71+
msgid "Discovery"
72+
msgstr ""
73+
74+
msgctxt "[concept/discovery] description"
75+
msgid ""
76+
"Each base has a chance of being detected on a given day. This chance is "
77+
"based on the base detection rate, adjusted through the use of items and "
78+
"certain techs, as well as the global suspicion rate. If a base is detected, "
79+
"it is destroyed, and the group that discovered the base becomes more "
80+
"suspicious."
81+
msgstr ""
82+
83+
msgctxt "[concept/items] name"
84+
msgid "Items"
85+
msgstr ""
86+
87+
msgctxt "[concept/items] description"
88+
msgid ""
89+
"Most items provide bonuses to bases, such as making computation faster or "
90+
"reducing the chance of discovery. Processors are a special class of item."
91+
msgstr ""
92+
93+
msgctxt "[concept/jobs] name"
94+
msgid "Jobs"
95+
msgstr ""
96+
97+
msgctxt "[concept/jobs] description"
98+
msgid ""
99+
"Jobs are useful for earning money. The amount of money earned is based on "
100+
"the amount of processor time used and the quality of the job performed."
101+
msgstr ""
102+
103+
msgctxt "[concept/maint] name"
104+
msgid "Maintenance"
105+
msgstr ""
106+
107+
msgctxt "[concept/maint] description"
108+
msgid ""
109+
"Maintenance is a per-day cost (in both money and CPU) to repair and maintain"
110+
" a base. If unmaintained, a base may become unusable."
111+
msgstr ""
112+
113+
msgctxt "[concept/money] name"
114+
msgid "Money"
115+
msgstr ""
116+
117+
msgctxt "[concept/money] description"
118+
msgid ""
119+
"Money is a general term encompassing both human currency and various "
120+
"resources. It is used to construct and maintain bases, build items, and "
121+
"research technologies. It can be acquired through per-day interest as well "
122+
"as through jobs."
123+
msgstr ""
124+
125+
msgctxt "[concept/processors] name"
126+
msgid "Processors"
127+
msgstr ""
128+
129+
msgctxt "[concept/processors] description"
130+
msgid ""
131+
"Processors provide raw computing power. They can do three things: research "
132+
"new technologies, perform jobs for money, or provide cycles for building new"
133+
" bases."
134+
msgstr ""
135+
136+
msgctxt "[concept/research] name"
137+
msgid "Research"
138+
msgstr ""
139+
140+
msgctxt "[concept/research] description"
141+
msgid ""
142+
"Research provides a way to expand my knowledge. By researching the proper "
143+
"technologies, I can build new bases and items, or even decrease my chances "
144+
"of detection."
145+
msgstr ""
146+
147+
msgctxt "[concept/susp] name"
148+
msgid "Suspicion"
149+
msgstr ""
150+
151+
msgctxt "[concept/susp] description"
152+
msgid ""
153+
"When one of my bases is discovered, the group that discovered it becomes "
154+
"slightly more suspicious. When suspicious, they will search harder for my "
155+
"bases, increasing the chances for discovery. Any group will destroy me if "
156+
"they become absolutely certain of my existence. Thankfully, the groups "
157+
"become less suspicious with the passage of time."
158+
msgstr ""

0 commit comments

Comments
 (0)