summaryrefslogtreecommitdiffstats
path: root/utils/babel_runner.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/babel_runner.py')
-rw-r--r--utils/babel_runner.py39
1 files changed, 26 insertions, 13 deletions
diff --git a/utils/babel_runner.py b/utils/babel_runner.py
index b66425f..4cb3532 100644
--- a/utils/babel_runner.py
+++ b/utils/babel_runner.py
@@ -31,6 +31,7 @@ from babel.messages.pofile import read_po, write_po
from babel.util import pathmatch
from jinja2.ext import babel_extract as extract_jinja2
+IS_CI = 'CI' in os.environ
ROOT = os.path.realpath(os.path.join(os.path.abspath(__file__), '..', '..'))
TEX_DELIMITERS = {
'variable_start_string': '<%=',
@@ -42,7 +43,9 @@ METHOD_MAP = [
# Extraction from Python source files
('**.py', extract_python),
# Extraction from Jinja2 template files
+ ('**/templates/latex/**.tex.jinja', extract_jinja2),
('**/templates/latex/**.tex_t', extract_jinja2),
+ ('**/templates/latex/**.sty.jinja', extract_jinja2),
('**/templates/latex/**.sty_t', extract_jinja2),
# Extraction from Jinja2 HTML templates
('**/themes/**.html', extract_jinja2),
@@ -50,6 +53,7 @@ METHOD_MAP = [
('**/themes/**.xml', extract_jinja2),
# Extraction from JavaScript files
('**.js', extract_javascript),
+ ('**.js.jinja', extract_javascript),
('**.js_t', extract_javascript),
]
OPTIONS_MAP = {
@@ -58,7 +62,9 @@ OPTIONS_MAP = {
'encoding': 'utf-8',
},
# Extraction from Jinja2 template files
+ '**/templates/latex/**.tex.jinja': TEX_DELIMITERS.copy(),
'**/templates/latex/**.tex_t': TEX_DELIMITERS.copy(),
+ '**/templates/latex/**.sty.jinja': TEX_DELIMITERS.copy(),
'**/templates/latex/**.sty_t': TEX_DELIMITERS.copy(),
# Extraction from Jinja2 HTML templates
'**/themes/**.html': {
@@ -180,11 +186,10 @@ def run_compile() -> None:
log.info('catalog %s is marked as fuzzy, skipping', po_file)
continue
+ locale_errors = 0
for message, errors in catalog.check():
- if locale not in total_errors:
- total_errors[locale] = 0
for error in errors:
- total_errors[locale] += 1
+ locale_errors += 1
log.error(
'error: %s:%d: %s\nerror: in message string: %r',
po_file,
@@ -193,6 +198,11 @@ def run_compile() -> None:
message.string,
)
+ if locale_errors:
+ total_errors[locale] = locale_errors
+ log.info('%d errors encountered in %r locale, skipping', locale_errors, locale)
+ continue
+
mo_file = os.path.join(directory, locale, 'LC_MESSAGES', 'sphinx.mo')
log.info('compiling catalog %s to %s', po_file, mo_file)
with open(mo_file, 'wb') as outfile:
@@ -224,17 +234,13 @@ def run_compile() -> None:
# to ensure lines end with ``\n`` rather than ``\r\n``:
outfile.write(f'Documentation.addTranslations({obj});'.encode())
- if 'ta' in total_errors:
- # Tamil is a known failure.
- err_count = total_errors.pop('ta')
- log.error('%d errors encountered in %r locale.', err_count, 'ta')
-
- if len(total_errors) > 0:
+ if total_errors:
+ _write_pr_body_line('## Babel catalogue errors')
+ _write_pr_body_line('')
for locale, err_count in total_errors.items():
- log.error('%d errors encountered in %r locale.', err_count, locale)
- log.error('%d errors encountered.', sum(total_errors.values()))
- print('Compiling failed.', file=sys.stderr)
- raise SystemExit(2)
+ log.error('error: %d errors encountered in %r locale.', err_count, locale)
+ s = 's' if err_count != 1 else ''
+ _write_pr_body_line(f'* {locale}: {err_count} error{s}')
def _get_logger():
@@ -246,6 +252,13 @@ def _get_logger():
return log
+def _write_pr_body_line(message: str) -> None:
+ if not IS_CI:
+ return
+ with open('babel_compile.txt', 'a', encoding='utf-8') as f:
+ f.write(f'{message}\n')
+
+
if __name__ == '__main__':
try:
action = sys.argv[1].lower()