- Sep 17, 2018
- 4,399
- 5,614
Took a while to figure out, but the root cause and solution are pretty simple at the end. Translation works by extracting the game's texts with a unique ID into a file where they can be translated (the files that you can download as community translations). Basically there you find something like:Wow! Nice work. Thank you.
Can you please tell me how you fixed this?
Code:
translate <language> <label>_<id>:
<character> "<translated text>"
One problem was that when the mod introduces new labels, that lookup does not work because the label does not match, while the id would. I identified some places where that would be the case and tried to change the mod to use the original label instead. I sure missed some places, meaning it will still not always work.
But the main problem is that sometimes, to make the id unique, Renpy decides to add a suffix "_1" to it (increasing the number each time a new ambiguous id is found). It appears, that randomly this affects modded files in total, replacing all id's with the ones adding a suffix, and the whole file will never be translated. I had to dig into Renpy coding to replace all those labels back during translation lookup time.
The method I had to replace is inside Renpy libraries:
Code:
old_lookup = renpy.ast.Translate.lookup
def my_lookup(self):
rv = old_lookup(self)
if self.identifier.endswith("_1") or self.identifier.endswith("_2") or self.identifier.endswith("_3") or self.identifier.endswith("_4") or self.identifier.endswith("_5"):
try:
rv.what = renpy.game.script.translator.lookup_translate(self.identifier[:-2], getattr(self, "alternate", None)).what
except KeyError:
pass
return rv
renpy.ast.Translate.lookup = my_lookup