forked from PTSnoop/HoI4-to-Stellaris-Converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
localisation.py
78 lines (65 loc) · 3.35 KB
/
localisation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python3
import naive_parser
import getCountryNames
import universe
import sys
import numpy
import codecs
class Localisation:
def __init__(self, savefile, hoi4path, parser, theUniverse):
self.savefile = savefile
self.hoi4path = hoi4path
self.universe = theUniverse
self.parser = parser
self.localise()
def localise(self):
self.empireNames = {}
countryNames = getCountryNames.getCountryNames(self.hoi4path)
for empire in self.universe.empires:
longtag = empire.longTag()
empireName = countryNames[longtag]
empireName = empireName.replace("Empire","Star Empire")
if " " not in empireName:
if empire.government == "communism":
govs = ["People's Republic of &","People's Republic of &","Socialist Republic", "People's Democratic Republic of &", "Planetary Republic", "Democratic People's Republic","Republic of &","Union","Alliance of ^ Planets","&","Space &"]
elif empire.government == "democratic":
govs = ["Republic","Republic","Commonwealth","Union","United ^ Planets","Empire","United Worlds", "Planetary Republic", "Alliance of ^ Planets","&","Space &"]
elif empire.government == "fascism":
govs = ["Empire","Empire","Greater ^ Empire","Star Empire","Imperium","Hegemony","&","Space &","Planetary Empire"]
else:
govs = ["Empire","United Worlds","Planetary Alliance","Empire of ^ Planets","Alliance of ^ Planets","&","Space &"]
countryName = empireName
countryAdj = countryNames[longtag+"_ADJ"]
empireName = numpy.random.choice(govs)
if "&" in empireName:
empireName = empireName.replace("&",countryName)
elif "^" in empireName:
empireName = empireName.replace("^",countryAdj)
else:
empireName = countryAdj + " " + empireName
self.empireNames[longtag] = empireName
def writeLocalisation(self):
base = open("files/convertertest_l_english.yml",encoding="utf-8").read()
localisation = base
for tag in self.empireNames:
localisation += ' {}:0 "{}"\n'.format(tag,self.empireNames[tag])
localisation += "\n"
for tag in self.empireNames:
localisation += ' NAME_{}:0 "{}"\n'.format(tag,self.empireNames[tag])
localisation += "\n"
for tag in self.empireNames:
smalltag = tag.split("_")[0]
localisation += ' name_list_{}_names:0 "{}"\n'.format(smalltag,self.empireNames[tag])
localisation += "\n"
history = self.universe.GetHistory()
history = history.replace("\n","\\n")
localisation += ' START_SCREEN_CONVERTED:0 "{}"\n\n'.format(history)
open("outputMod/localisation/convertertest_l_english.yml","w",encoding="utf-8-sig").write(localisation)
def writeSyncedLocalisation(self):
synced = "l_default:\n"
for tag in self.empireNames:
synced += ' NAME_{}: "{}"\n'.format(tag,self.empireNames[tag])
synced += "\n"
syncedFile = open("outputMod/localisation_synced/converter_names.yml","w",encoding="utf-8-sig")
#syncedFile.write(u'\ufeff')
syncedFile.write(synced)