Page 1 of 1

testing translations locally

Posted: Sun Aug 23, 2020 3:49 pm
by gyorokpeter
Is there a way to download the translations and inject them into the game to save the waiting for the next release and also allow for a more interactive workflow?
Crowdin allows download but it gives a zip containing .ini files, and there are no .ini files in the Factorio directory inside Steam.

Re: testing translations locally

Posted: Thu Aug 27, 2020 9:03 am
by TheEnemy42
None that I know of but I'd love the opportunity, especially since the slow-down post release. I'm still fine tuning the translations and seeing it in-game helps a lot for context.

Re: testing translations locally

Posted: Thu Aug 27, 2020 12:20 pm
by eradicator
gyorokpeter wrote:
Sun Aug 23, 2020 3:49 pm
Crowdin allows download but it gives a zip containing .ini files, and there are no .ini files in the Factorio directory inside Steam.
Not sure how the crowdin files look inside, but factorio locale.cfg files *are* ini files, they just have a different file extension. So if you're lucky it might be enough to rename them.

Re: testing translations locally

Posted: Wed Sep 16, 2020 8:33 am
by gyorokpeter
Turns out it's not a simple rename and overwrite. There are minor syntax differences in the files downloaded from Crowdin that Factorio chokes on:

unconfirmed-mod-changes="__1__ __plural_for_parameter_1_ {1 = mod | rest = mods} __ megváltozott.
CONTEXTREQUEST"

This two-line string is represented as a single string with an embedded \n in the equivalent .cfg file. (Ironically the translation itself is garbage and needs to be replaced.)

So I came up with the following conversion code:

Code: Select all

import subprocess
import os
import re

temp = "D:/Temp/FactorioTranslations"

subprocess.run(["D:/Program Files/7-Zip/7z", "e", "D:/Temp/Factorio (hu).zip", "-y", "-o"+temp])
files = os.listdir(temp)

def rpl1(src,dst):
    lines=[]
    for line in open(src, encoding='utf8'):
        if line[-1:] == "\n":
            line = line[:-1]
        if len(line) == 0:
            pass
        elif re.match("^\[.*\]$", line):
            lines.append(line)
        elif re.match("^[^=]*=", line):
            lines.append(line)
        else:
            lines[len(lines)-1] = lines[len(lines)-1]+"\\n"+line
    open(dst, encoding='utf8', mode='w').write("\n".join(lines))

def rpl(curr):
    currf = os.listdir(curr)
    if not "hu" in currf:
        print("no \"hu\" in {}".format(curr))
        return
    nxt = os.path.join(curr,"hu")
    nxtf = os.listdir(nxt)
    for f in nxtf:
        if ".cfg" in f:
            nxtf2 = os.path.join(nxt, f)
            srcf = os.path.join(temp, f.replace(".cfg", ".ini"))
            if not os.path.isfile(srcf):
                print("no localized file for: {}".format(srcf))
            else:
                print("replacing {} with {}".format(nxtf2, srcf))
                rpl1(srcf, nxtf2)

def rp(curr):
    currf = os.listdir(curr)
    for f in currf:
        nxt = os.path.join(curr, f)
        if f == "locale":
            rpl(nxt)
        elif os.path.isdir(nxt):
            rp(nxt)

rp("D:/Program Files/Steam/steamapps/common/Factorio")

Re: testing translations locally

Posted: Wed Sep 16, 2020 3:46 pm
by valneq
Well … if the translation itself does not contain newline characters, but \n instead, it's already half way there …

Re: testing translations locally

Posted: Sun Sep 27, 2020 6:48 am
by Dev-iL
Whenever I wanted to test translations in the past, I would simply modify the .cfg files directly (and reload the game). Of course this is not very useful when you want to modify a large number of strings, but very convenient otherwise. Another alternative, for those who don't want to edit the original files, is to copy the relevant cfg files into a new folder with the same directory structure as the Factorio root, and turn it into a mod you can then turn on\off in-game (I'm not sure about specifics because I haven't done this in years, but that's the general idea).

Re: testing translations locally

Posted: Wed Jan 27, 2021 11:00 pm
by gyorokpeter
I have come up with a script that downloads all the strings from Crowdin using the Crowdin API. It works well and doesn't actually need the text conversion, although it does need to sort the strings into files and then match the file names and locations with those in the game directory.

https://github.com/gyorokpeter/factorio ... ownload.py