Skip to content

Commit

Permalink
[Tools] Refactor updatets to support two-lang mods
Browse files Browse the repository at this point in the history
  • Loading branch information
chennes committed Sep 17, 2021
1 parent 5fd21f8 commit 4c20726
Showing 1 changed file with 34 additions and 61 deletions.
95 changes: 34 additions & 61 deletions src/Tools/updatets.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,60 +63,21 @@
"src/Mod/Sandbox",
"src/Mod/TemplatePyMod"]


# python folders that need a special pylupdate command
PyCommands = [["src/Mod/Draft",
'pylupdate `find ./ -name "*.py"` Resources/ui/*.ui -ts Resources/translations/Draft.ts'],
["src/Mod/Arch",
'pylupdate `find ./ -name "*.py"` Resources/ui/*.ui -ts Resources/translations/Arch.ts'],
["src/Mod/OpenSCAD",
"pylupdate *.py Resources/ui/*.ui -ts Resources/translations/OpenSCAD.ts"],
["src/Mod/Start",
"lupdate Gui/*.ui Gui/*.cpp -ts Gui/Resources/translations/StartPage.ts"],
["src/Mod/Start",
"pylupdate StartPage/*.py -ts Gui/Resources/translations/StartPagepy.ts"],
["src/Mod/Start",
'lconvert -i Gui/Resources/translations/StartPagepy.ts Gui/Resources/translations/StartPage.ts -o Gui/Resources/translations/StartPage.ts'],
["src/Mod/Start",
'rm Gui/Resources/translations/StartPagepy.ts'],
["src/Mod/Path",
'pylupdate `find ./ -name "*.py"` -ts Gui/Resources/translations/Pathpy.ts'],
["src/Mod/Path",
'lconvert -i Gui/Resources/translations/Pathpy.ts Gui/Resources/translations/Path.ts -o Gui/Resources/translations/Path.ts'],
["src/Mod/Path",
'rm Gui/Resources/translations/Pathpy.ts'],
["src/Mod/Fem",
'pylupdate `find ./ -name "*.py"` -ts Gui/Resources/translations/Fempy.ts'],
["src/Mod/Fem",
'lconvert -i Gui/Resources/translations/Fempy.ts Gui/Resources/translations/Fem.ts -o Gui/Resources/translations/Fem.ts'],
["src/Mod/Fem",
'rm Gui/Resources/translations/Fempy.ts'],
["src/Mod/Tux",
'pylupdate `find ./ -name "*.py"` -ts Resources/translations/Tux.ts'],
["src/Mod/Part",
'pylupdate `find ./ -name "*.py"` -ts Gui/Resources/translations/Partpy.ts'],
["src/Mod/Part",
'lconvert -i Gui/Resources/translations/Partpy.ts Gui/Resources/translations/Part.ts -o Gui/Resources/translations/Part.ts'],
["src/Mod/Part",
'rm Gui/Resources/translations/Partpy.ts'],
["src/Mod/PartDesign",
'pylupdate `find ./ -name "*.py"` -ts Gui/Resources/translations/PartDesignpy.ts'],
["src/Mod/PartDesign",
'lconvert -i Gui/Resources/translations/PartDesignpy.ts Gui/Resources/translations/PartDesign.ts -o Gui/Resources/translations/PartDesign.ts'],
["src/Mod/PartDesign",
'rm Gui/Resources/translations/PartDesignpy.ts'],
["src/Mod/Image",
'pylupdate `find ./ -name "*.py"` -ts Gui/Resources/translations/Imagepy.ts'],
["src/Mod/Image",
'lconvert -i Gui/Resources/translations/Imagepy.ts Gui/Resources/translations/Image.ts -o Gui/Resources/translations/Image.ts'],
["src/Mod/Image",
'rm Gui/Resources/translations/Imagepy.ts'],
["src/Mod/AddonManager",
"pylupdate *.py *.ui -ts Resources/translations/AddonManager.ts"],
]

# add python folders to exclude list
for c in PyCommands:
DirFilter.append(c[0]+"$")
pyFolders = {
"AddonManager" : "Resources/translations",
"Arch" : "Resources/translations",
"Draft" : "Resources/translations",
"Fem" : "Gui/Resources/translations",
"Image" : "Gui/Resources/translations",
"OpenSCAD" : "Resources/translations",
"Part" : "Gui/Resources/translations",
"PartDesign" : "Gui/Resources/translations",
"Path" : "Gui/Resources/translations",
"Start" : "Gui/Resources/translations",
"Tux" : "Resources/translations"
}

QMAKE = ""
LUPDATE = ""
Expand Down Expand Up @@ -211,15 +172,25 @@ def update_translation(path):
os.remove(jsonfile)
os.chdir(cur)

def update_python_translation(item):
def update_python_translation(mod, pathToTranslations):

global PYLUPDATE, LCONVERT
cur = os.getcwd()
os.chdir(item[0])
execline = item[1].replace("pylupdate",PYLUPDATE)
execline = execline.replace("lconvert",LCONVERT)
print("Executing special command in ",item[0],": ",execline)
os.system(execline)
os.chdir(f"src/Mod/{mod}")
execline0 = f'touch {pathToTranslations}/{mod}.ts'
execline1 = f'{PYLUPDATE} `find ./ -name "*.py"` -ts {pathToTranslations}/{mod}py.ts'
execline2 = f'{LCONVERT} -i {pathToTranslations}/{mod}py.ts {pathToTranslations}/{mod}.ts -o {pathToTranslations}/{mod}.ts'
execline3 = f'rm {pathToTranslations}/{mod}py.ts'
print(f"Executing special commands in src/Mod/{mod}:")
print(execline0)
os.system(execline0)
print(execline1)
os.system(execline1)
print(execline2)
os.system(execline2)
print(execline3)
os.system(execline3)
print()
os.chdir(cur)

def main():
Expand All @@ -239,9 +210,11 @@ def main():
dirs = filter(filter_dirs, dirs)
for i in dirs:
update_translation(i)
for j in PyCommands:
update_python_translation(j)
for mod,transPath in pyFolders.items():
update_python_translation(mod, transPath)
print("\nIf updatets.py was run successfully, the next step is to run ./src/Tools/updatecrowdin.py")

if __name__ == "__main__":
main()


0 comments on commit 4c20726

Please sign in to comment.