-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup_translate.py
More file actions
41 lines (30 loc) · 1.1 KB
/
setup_translate.py
File metadata and controls
41 lines (30 loc) · 1.1 KB
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
from setuptools import Command as cmd
from setuptools.command.build import build as _build
import os
class build_trans(cmd):
description = "Compile .po files into .mo files"
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
tool = "/usr/bin/msgfmt"
if not os.path.isfile(tool):
return
repo_root = os.path.dirname(os.path.abspath(__file__))
src_folder = os.path.join(repo_root, "src")
po_folder = os.path.join(repo_root, "po")
PluginLanguageDomain = "PlutoTV" # same as in __init__.py
for lang in [f[:-3] for f in os.listdir(po_folder) if f.endswith(".po")]:
os.makedirs((destdir := os.path.join(src_folder, "locale", lang, "LC_MESSAGES")), exist_ok=True)
command = "%s '%s' -o '%s'" % (tool, os.path.join(po_folder, "%s.po" % lang), os.path.join(destdir, "%s.mo" % PluginLanguageDomain))
if os.system(command) != 0:
raise Exception("Failed to compile: " + command)
class build(_build):
sub_commands = _build.sub_commands + [("build_trans", None)]
def run(self):
_build.run(self)
cmdclass = {
"build": build,
"build_trans": build_trans,
}