winterheart / RimTranslate

Tool for translation RimWorld
GNU General Public License v3.0
6 stars 2 forks source link

Some small problems #1

Open ghost opened 6 years ago

ghost commented 6 years ago

Hello,

i really like you tool and tried to start a routine with it for translating. But i ran into some errors.

  1. 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)

  2. 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')

  3. 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.

  4. 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.

winterheart commented 6 years ago

Hello.

  1. XML file will be generated only if corresponding PO file has at least one translated message. Your changes made only for logging, I don't quite follow, how it helps.
  2. Fixed in 0.6.7.
  3. I've replaced Defs to Def structure, you need move old generated po/xml files, and regenerate again.

Just curious, to what language you translate?

ghost commented 6 years ago

Hello,

thanks for you fast reply.

  1. I just rechecked this. Added new Translations in the po files, when I try to export the error is there again. It is only the Logging info, but it seems the script aborts if the logging fails and the logging fails because pofilename is not defined at this point. So I put my fix back in and its working again.
  2. Thanks
  3. I see, but I think you didn't understand me right. Let me explain a little bit better. I try to translate a mod, this mod has xml files in these 2 folders "ThingDefs_Buildings" and "ThingDefs_Items" but the xml files under Languages need all to be in 1 folder called ThingDef. Your changes put them in ThingDef_Items and ThingDef_Buildings.

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")
ghost commented 6 years ago

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 it needs to go into the "ResearchTabDef" folder in the language folder not in the ResearchProjectDef but thats where it will land most of the time, because a lot of modder put their Tab Definition inside Defs/ResearchProjectDefs. Thats okay for adding it to the mod, but not for translatin. If I manage to fix that, I post it here.

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.