Skip to content

Commit

Permalink
Import waftlib for tranlate-module script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hussam-Suleiman committed Dec 5, 2024
1 parent b1300ea commit 3d237db
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions bin/translate-modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import polib
import shutil
import tempfile

from waftlib import (
ODOO_DIR,
ADDONS_DIR,
SRC_DIR,
)

HELP_TEXT = """
This script will generate new .po files for certain modules, and certain
Expand Down Expand Up @@ -35,7 +39,6 @@
translations.
"""


arguments = {}
compendium = {}
deepl = None
Expand All @@ -61,13 +64,13 @@ def deepl_lang(lang):

if not lang in compendium:
return

# Try translating with the compendium first
for entry in pofile.untranslated_entries():
if entry.msgid in compendium[lang]:
entry.msgstr = compendium[lang][entry.msgid]
continue

# Translate all missing entries in one request
if 'use-translation-service' in arguments:
untranslated_entries = pofile.untranslated_entries()
Expand All @@ -90,13 +93,14 @@ def deepl_lang(lang):

def generate_new_translations(module_name, language):
global arguments, temp_file
os.system('./run --stop-after-init --log-level error -d "%s" -l %s --modules "%s" --i18n-export "%s" ' % (arguments['database'], language, module_name, temp_file))
os.system('./run --stop-after-init --log-level error -d "%s" -l %s --modules "%s" --i18n-export "%s" ' % (
arguments['database'], language, module_name, temp_file))
return polib.pofile(temp_file)


def load_compendium(folder, langs=None):
dictionary = {}

for subdir, dirs, files in os.walk(folder):
for filename in files:
if filename.endswith('.po'):
Expand Down Expand Up @@ -136,7 +140,7 @@ def find_entry(pofile, msgid):
if old_entry:
entry.msgstr = old_entry.msgstr
existing_msgids.append(entry.msgid)

# Append unused old entries as comments:
for entry in old_translations.translated_entries():
if not entry.msgid in existing_msgids:
Expand Down Expand Up @@ -176,7 +180,7 @@ def parse_arguments():

def main():
global arguments, compendium, deepl, temp_file, translator

try:
arguments = parse_arguments()
except getopt.GetoptError as err:
Expand All @@ -199,7 +203,7 @@ def main():
return 1
else:
args['database'] = database

if 'module-folder' in args and len(args['module-folder']) > 0:
addon_folder = args['module-folder']
addons = os.listdir(os.path.join(SRC_DIR, addon_folder))
Expand All @@ -224,7 +228,7 @@ def main():
print("Warning: no languages specified. Loading all languages, which "
"may take a long time. To speed up this process, specify "
"languages to process less like so: -l nl,de,fr",
file=sys.stderr)
file=sys.stderr)
langs = args['languages'] if 'languages' in args else None

# Initialize
Expand Down

0 comments on commit 3d237db

Please sign in to comment.