Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlovetox <philipp@hoerist.com>2022-04-19 19:28:16 +0300
committerlovetox <philipp@hoerist.com>2022-04-19 19:28:16 +0300
commit945773037577c6eaf64c1075676e6dd1e22361d7 (patch)
tree36d29484a6f95aa0313bc78a4e3c49272aebc243
parent9baa9fc1568ea7f6df3c5ceef67f5defa65a6625 (diff)
refactor: Move translation update into own module
The server needs to run the script and it has only python 3.7 available
-rw-r--r--scripts/update_translations.py85
-rw-r--r--setup.py85
2 files changed, 86 insertions, 84 deletions
diff --git a/scripts/update_translations.py b/scripts/update_translations.py
new file mode 100644
index 000000000..678057417
--- /dev/null
+++ b/scripts/update_translations.py
@@ -0,0 +1,85 @@
+# File needs to stay compatible to Python 3.7
+# because its run on the Gajim webserver
+
+
+import re
+import subprocess
+from pathlib import Path
+
+
+TRANS_DIR = Path('po')
+TRANS_TEMPLATE = TRANS_DIR / 'gajim.pot'
+REPO_DIR = Path(__file__).resolve().parent.parent
+
+
+TRANSLATABLE_FILES = [
+ 'gajim/**/*.py',
+ 'gajim/**/*.ui',
+ 'data/org.gajim.Gajim.desktop.in',
+ 'data/org.gajim.Gajim.appdata.xml.in',
+]
+
+
+def template_is_equal(old_template_path: Path, new_template: str) -> bool:
+ with open(old_template_path, 'r') as f:
+ old_template = f.read()
+
+ pattern = r'"POT-Creation-Date: .*\n"'
+
+ old_template = re.sub(pattern, '', old_template, count=1)
+ new_template = re.sub(pattern, '', new_template, count=1)
+
+ return old_template == new_template
+
+
+def update_translation_template() -> bool:
+ paths: list[Path] = []
+ for file_path in TRANSLATABLE_FILES:
+ paths += list(REPO_DIR.rglob(file_path))
+
+ cmd = [
+ 'xgettext',
+ '-o', '-',
+ '-c#',
+ '--from-code=utf-8',
+ '--keyword=Q_',
+ '--no-location',
+ '--sort-output',
+ '--package-name=Gajim'
+ ]
+
+ for path in paths:
+ cmd.append(str(path))
+
+ result = subprocess.run(cmd,
+ cwd=REPO_DIR,
+ text=True,
+ check=True,
+ capture_output=True)
+
+ template = result.stdout
+
+ if (TRANS_TEMPLATE.exists() and
+ template_is_equal(TRANS_TEMPLATE, template)):
+ # No new strings were discovered
+ return False
+
+ with open(TRANS_TEMPLATE, 'w') as f:
+ f.write(template)
+ return True
+
+
+def update_translation_files() -> None:
+ for file in TRANS_DIR.glob('*.po'):
+ subprocess.run(['msgmerge',
+ '-U',
+ '--sort-output',
+ str(file),
+ TRANS_TEMPLATE],
+ cwd=REPO_DIR,
+ check=True)
+
+
+if __name__ == '__main__':
+ update_translation_template()
+ update_translation_files()
diff --git a/setup.py b/setup.py
index d86155b60..5698bc6ba 100644
--- a/setup.py
+++ b/setup.py
@@ -8,12 +8,10 @@ import sys
if sys.version_info < (3, 9):
sys.exit('Gajim needs Python 3.9+')
-import re
import subprocess
from pathlib import Path
from setuptools import setup
-from setuptools import Command
from setuptools.command.build_py import build_py as _build
from setuptools.command.install import install as _install
@@ -25,12 +23,7 @@ MAN_FILES = [
META_FILES = [
('data/org.gajim.Gajim.desktop', 'share/applications', '--desktop'),
('data/org.gajim.Gajim.appdata.xml', 'share/metainfo', '--xml')]
-TRANSLATABLE_FILES = [
- 'gajim/**/*.py',
- 'gajim/**/*.ui',
- 'data/org.gajim.Gajim.desktop.in',
- 'data/org.gajim.Gajim.appdata.xml.in',
-]
+
TRANS_DIR = Path('po')
TRANS_TEMPLATE = TRANS_DIR / 'gajim.pot'
@@ -53,66 +46,6 @@ def newer(source: Path, target: Path) -> bool:
return mtime1 > mtime2
-def template_is_equal(old_template_path: Path, new_template: str) -> bool:
- with open(old_template_path, 'r') as f:
- old_template = f.read()
-
- pattern = r'"POT-Creation-Date: .*\n"'
-
- old_template = re.sub(pattern, '', old_template, count=1)
- new_template = re.sub(pattern, '', new_template, count=1)
-
- return old_template == new_template
-
-
-def update_translation_template() -> bool:
- paths: list[Path] = []
- for file_path in TRANSLATABLE_FILES:
- paths += list(REPO_DIR.rglob(file_path))
-
- cmd = [
- 'xgettext',
- '-o', '-',
- '-c#',
- '--from-code=utf-8',
- '--keyword=Q_',
- '--no-location',
- '--sort-output',
- '--package-name=Gajim'
- ]
-
- for path in paths:
- cmd.append(str(path))
-
- result = subprocess.run(cmd,
- cwd=REPO_DIR,
- text=True,
- check=True,
- capture_output=True)
-
- template = result.stdout
-
- if (TRANS_TEMPLATE.exists() and
- template_is_equal(TRANS_TEMPLATE, template)):
- # No new strings were discovered
- return False
-
- with open(TRANS_TEMPLATE, 'w') as f:
- f.write(template)
- return True
-
-
-def update_translation_files() -> None:
- for file in TRANS_DIR.glob('*.po'):
- subprocess.run(['msgmerge',
- '-U',
- '--sort-output',
- str(file),
- TRANS_TEMPLATE],
- cwd=REPO_DIR,
- check=True)
-
-
def build_translation() -> None:
for lang in ALL_LINGUAS:
po_file = TRANS_DIR / f'{lang}.po'
@@ -229,21 +162,6 @@ class install(_install):
_install.run(self)
-class update_translations(Command):
- description = "Update translation"
- user_options = []
-
- def initialize_options(self):
- pass
-
- def finalize_options(self):
- pass
-
- def run(self):
- update_translation_template()
- update_translation_files()
-
-
# only install subdirectories of data
data_files_app_icon = [
("share/icons/hicolor/scalable/apps",
@@ -258,7 +176,6 @@ setup(
cmdclass={
'build_py': build,
'install': install,
- 'update_translations': update_translations,
},
entry_points={
'console_scripts': [