From 99755ac611e5f78994fc3ba9385db0813f13acd0 Mon Sep 17 00:00:00 2001 From: geekcj12 Date: Thu, 18 Jun 2026 14:22:01 +0800 Subject: [PATCH] build(docker): compile backend trasnlations during image build --- contrib/container/Dockerfile | 3 +++ tasks.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/contrib/container/Dockerfile b/contrib/container/Dockerfile index 0427dd15ed..16418375e6 100644 --- a/contrib/container/Dockerfile +++ b/contrib/container/Dockerfile @@ -145,6 +145,9 @@ ENV PATH=/root/.local/bin:$PATH COPY --from=builder_stage ${INVENTREE_BACKEND_DIR}/InvenTree/web/static/web ${INVENTREE_BACKEND_DIR}/InvenTree/web/static/web COPY --from=builder_stage /root/.local /root/.local +# Compile Django backend translations during image build +RUN bash -c "cd '${INVENTREE_HOME}' && invoke int.backend-compilemessages" + # Launch the production server CMD ["sh", "-c", "exec gunicorn -c ./gunicorn.conf.py InvenTree.wsgi -b ${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT} --chdir ${INVENTREE_BACKEND_DIR}/InvenTree"] diff --git a/tasks.py b/tasks.py index 4f94ff57f6..b59a43d738 100644 --- a/tasks.py +++ b/tasks.py @@ -906,6 +906,23 @@ def backend_trans(c, verbose: bool = False): success('Backend translations compiled successfully') +@task(help={'verbose': 'Print verbose output'}) +@state_logger('backend_compilemessages') +def backend_compilemessages(c, verbose: bool = False): + """Compile backend Django translation files without loading InvenTree settings.""" + info('Compiling backend translations...') + + cmd = 'python3 -m django compilemessages' + + if verbose: + cmd += ' -v 1' + else: + cmd += ' -v 0' + + run(c, cmd, manage_py_dir()) + success('Backend translations compiled successfully') + + @task( help={ 'clean': 'Clean up old backup files', @@ -2490,6 +2507,7 @@ internal = Collection( clear_generated, export_settings_definitions, export_definitions, + backend_compilemessages, frontend_build, frontend_check, frontend_compile,