Open ghost opened 6 years ago
Hello.
Just curious, to what language you translate?
Hello,
thanks for you fast reply.
I am from Germany and translate in German. We have characters like ü, ä, ö and ß
I tried to fix this myself, but i never worked with python. But I had some success. I could generate the right path for 3. and 4. but I havent figured out how to get the new folder to the part of the script where it actualy generates the PO file.
def create_pot_file_from_def(filename):
"""Create POT file (only source strings exists) from given filename"""
doc = etree.parse(filename)
# 9-tailed Check for Files from Patches folder, if true extract right folder to save and changes filename to it
check = "Patches"
is_patches = filename.find(check)
if is_patches is not -1:
for defName in defNames:
for defName_node in doc.findall("//" + defName):
if defName_node is not None:
# 9-tailed Modifikation
parent_node = defName_node.getparent()
folder = parent_node.tag
filename = filename.replace("Patches", folder)
# 9-tailed Check for ThingDefs_ folders, if true changes filename to ThingDef
check = "ThingDefs_"
is_patches = filename.find(check)
if is_patches is not -1:
filename = re.sub(r"ThingDefs_(.*)\\", "ThingDef\\\\", filename)
po_file = polib.POFile()
basefile = filename.split(args.source_dir, 1)[1]
logging.debug("PO File '%s'" % (basefile))
With this change I see the right Path in the log, but it still generates the old path. So I think I need to get basefile to po.save(pofilename).
Edit: But you change helps me a lot, I think I can fix problem 3 at least now. Still the Patches folder problem persits, as I need the parent_node.tag for the new filepath.
Edit 2: This works for the Things Problem:
# Replace Defs to Def, issue #1
file_dir = re.sub(r"ThingDefs_(.*)\\", "ThingDef\\\\", file_dir)
file_dir = file_dir.replace("Defs", "Def")
I think I got it. I added this part and till now, the Patch folder is generated right. I will confirm after I test the finished translation ingame.
´´´
logging.info('Generating PO-files from Patches')
# Parse Patches subdirectory
defs_source_dir = os.path.join(args.source_dir, 'Patches', '')
if os.path.isdir(defs_source_dir):
for root, dirs, files in os.walk(defs_source_dir):
for file in files:
if file.endswith('.xml'):
full_filename = os.path.join(root, file)
logging.info("Processing " + full_filename)
doc = etree.parse(full_filename)
folder = None
for defName in defNames:
for defName_node in doc.findall("//" + defName):
if defName_node is not None:
parent_node = defName_node.getparent()
folder = parent_node.tag
file_dir = full_filename.split(defs_source_dir, 1)[1]
if folder is not None:
newpath = os.path.join('', folder, file_dir)
file_dir = newpath
logging.info("Change Path " + newpath)
pot = create_pot_file_from_def(full_filename)
pofilename = os.path.join(args.po_dir, 'DefInjected', file_dir)
pofilename += '.po'
if os.path.exists(pofilename):
logging.info("Updating PO file " + pofilename)
po = polib.pofile(pofilename)
po.merge(pot)
else:
# Is there some useful info?
if len(pot) > 0:
directory = os.path.dirname(pofilename)
if not(os.path.exists(directory)):
logging.info("Creating directory " + directory)
os.makedirs(directory)
logging.info("Creating PO file " + pofilename)
po = pot
# If there compendium, fill entries with translation memory
if args.compendium:
for entry in po:
if entry.msgstr == '':
check_msg = compendium.find(entry.msgctxt, by='msgctxt', include_obsolete_entries=False)
if check_msg:
entry.msgstr = check_msg.msgstr
if 'fuzzy' not in entry.flags:
entry.flags.append('fuzzy')
if len(po):
po.save(pofilename)
else:
logging.error('%s is not directory or does not exists!' % defs_source_dir)
quit()
´´´
Edit: Everything seems good so far, at least with the patches folder. Found another special case. If a mod has its own Research Tab
And here it is: https://pastebin.com/vKJ5u7E6
I put the hole thing in Pastebin. Please watch out, I changed the meta generation, too and filled it with my dates on the top.
Hello,
i really like you tool and tried to start a routine with it for translating. But i ran into some errors.
When trying to Generating translated files it wouldn't do anything for me. It said pofilename was empty. I could fix that by changing: logging.info("Creating XML file " + pofilename) to logging.info("Creating XML file " + xml_filename)
My language needs special characters, but in the finished xml files these characters were wrong encoded. Fixed this by changing: target = open(xml_filename, 'w') to target = open(xml_filename, 'w', encoding='utf8')
Now the point I think I can't fix anymore. After creating a translation with your tool I had problems that a part of the translations didn't showed up. After some research I think it's the folder structure. When there are folders like ThingDefs_Buildings and ThingDefsItems under Defs your script copies them directly to the languages folder, but all files of these folders need to be combined into ThingDef folder. After changing this manually all translations showed up. I don't know if there are more special combining rules for translation. Maybe look at the core translation for hints. If you could include rewrite rules for the ThingDefs.... folder to ThingDef I can help with testing more combinations while translating mods and tell you about.
And one more, I am so sorry. If a mod adds new labels and description with a patch file, there will be no string for translation.