Search code examples
pythonpython-3.xyamlpyyaml

Wrong .yml format in "Stellaris" game


I want to parse yaml files that contain localization for "Stellaris". But all the time i have an error

"yaml mapping values are not allowed here"

I use pyyaml. The main problem is that all the localization files in game have lines like this:

trait_ruler_immortal:0 "Immortal"

But in yaml documentation and forums i can see that we have to make 'space' after a colon. I dont understand what this "0" symbol means. Interesting that game doesnt have any problems with parsing this files. Maybe this is special yaml format?

EDIT:

More code: l_english: crisis.2087.desc_psionic_synth:0 "A small number" EXTSYNTH_DIVINE_SPARK: "Divine Spark" EXTSYNTH_START_AT_3:0 "§GLeaders from this species start at skill level 3§!"


Solution

  • This is invalid YAML according to the spec. It may well be that Stellaris does some preprocessing on it before it gives the file to the YAML loader. We can only guess what happens here.

    The best shot parsing it is probably loading it to string and then doing

    input.replace(":0 ", ": ")
    

    before parsing it.