testing translations locally

Place to discuss translation contributions. Recent and
oncoming changes related to translation.
Post Reply
gyorokpeter
Inserter
Inserter
Posts: 29
Joined: Sat Jul 23, 2016 5:53 am
Contact:

testing translations locally

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

TheEnemy42
Inserter
Inserter
Posts: 47
Joined: Wed Jan 10, 2018 7:12 pm
Contact:

Re: testing translations locally

Post 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.
Currently primary Danish translator of Factorio. Feel free to contact me in regards to the translations.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5201
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: testing translations locally

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

gyorokpeter
Inserter
Inserter
Posts: 29
Joined: Sat Jul 23, 2016 5:53 am
Contact:

Re: testing translations locally

Post 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")

User avatar
valneq
Smart Inserter
Smart Inserter
Posts: 1134
Joined: Fri Jul 12, 2019 7:43 am
Contact:

Re: testing translations locally

Post by valneq »

Well … if the translation itself does not contain newline characters, but \n instead, it's already half way there …

User avatar
Dev-iL
Filter Inserter
Filter Inserter
Posts: 290
Joined: Thu Jul 02, 2015 2:48 pm
Contact:

Re: testing translations locally

Post 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).
Leading Hebrew translator of Factorio.

gyorokpeter
Inserter
Inserter
Posts: 29
Joined: Sat Jul 23, 2016 5:53 am
Contact:

Re: testing translations locally

Post 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

Post Reply

Return to “Translations”