diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 927419f8..11f165b7 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -96,10 +96,6 @@ def remove_heroku_files(): # don't remove the file if we are using travisci but not using heroku continue os.remove(file_name) - remove_heroku_build_hooks() - - -def remove_heroku_build_hooks(): shutil.rmtree("bin") @@ -444,8 +440,6 @@ def main(): if "{{ cookiecutter.use_heroku }}".lower() == "n": remove_heroku_files() - elif "{{ cookiecutter.frontend_pipeline }}" != "Django Compressor": - remove_heroku_build_hooks() if "{{ cookiecutter.use_docker }}".lower() == "n" and "{{ cookiecutter.use_heroku }}".lower() == "n": if "{{ cookiecutter.keep_local_envs_in_vcs }}".lower() == "y": diff --git a/{{cookiecutter.project_slug}}/bin/post_compile b/{{cookiecutter.project_slug}}/bin/post_compile index a9c94b39..16719f49 100644 --- a/{{cookiecutter.project_slug}}/bin/post_compile +++ b/{{cookiecutter.project_slug}}/bin/post_compile @@ -1,4 +1,5 @@ #!/usr/bin/env bash +{%- if cookiecutter.frontend_pipeline == "Django Compressor" %} compress_enabled() { python << END @@ -19,4 +20,7 @@ if compress_enabled then python manage.py compress fi +{%- endif %} + python manage.py collectstatic --noinput +python manage.py compilemessages -i site-packages diff --git a/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile index bbe45983..5a863ddc 100644 --- a/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile @@ -121,4 +121,8 @@ RUN chown django:django ${APP_HOME} USER django +RUN DATABASE_URL="" \ + DJANGO_SETTINGS_MODULE="config.settings.test" \ + python manage.py compilemessages + ENTRYPOINT ["/entrypoint"] diff --git a/{{cookiecutter.project_slug}}/locale/README.md b/{{cookiecutter.project_slug}}/locale/README.md new file mode 100644 index 00000000..b2a8a0ef --- /dev/null +++ b/{{cookiecutter.project_slug}}/locale/README.md @@ -0,0 +1,32 @@ +# Translations + +Start by configuring the `LANGUAGES` settings in `base.py`, by uncommenting languages you are willing to support. Then, translations strings will be placed in this folder when running: + +```bash +{% if cookiecutter.use_docker == 'y' %}docker-compose -f local.yml run --rm django {% endif %}python manage.py makemessages -all --no-location +``` + +This should generate `django.po` (stands for Portable Object) files under each locale `/LC_MESSAGES/django.po`. Each translatable string in the codebase is collected with its `msgid` and need to be translated as `msgstr`, for example: + +```po +msgid "users" +msgstr "utilisateurs" +``` + +Once all translations are done, they need to be compiled into `.mo` files (stands for Machine Object), which are the actual binary files used by the application: + +```bash +{% if cookiecutter.use_docker == 'y' %}docker-compose -f local.yml run --rm django {% endif %}python manage.py compilemessages +``` + +Note that the `.po` files are NOT used by the application directly, so if the `.mo` files are out of dates, the content won't appear as translated even if the `.po` files are up-to-date. + +## Production + +The production image runs `compilemessages` automatically at build time, so as long as your translated source files (PO) are up-to-date, you're good to go. + +## Add a new language + +1. Update the [`LANGUAGES` setting](https://docs.djangoproject.com/en/stable/ref/settings/#std-setting-LANGUAGES) to your project's base settings. +2. Create the locale folder for the language next to this file, e.g. `fr_FR` for French. Make sure the case is correct. +3. Run `makemessages` (as instructed above) to generate the PO files for the new language. diff --git a/{{cookiecutter.project_slug}}/locale/README.rst b/{{cookiecutter.project_slug}}/locale/README.rst deleted file mode 100644 index a501b7a1..00000000 --- a/{{cookiecutter.project_slug}}/locale/README.rst +++ /dev/null @@ -1,14 +0,0 @@ -Translations -============ - -Start by configuring `LANGUAGES` at settings, by uncommenting languages you are willing to support. - -Translations will be placed in this folder when running: - - python manage.py makemessages --all - -Then you should edit the .po files providing proper translations and then run the following for compiling the messages: - - python manage.py compilemessages - -Note: You may need to restart the django server for changes to take effect. diff --git a/{{cookiecutter.project_slug}}/locale/en_US/LC_MESSAGES/django.po b/{{cookiecutter.project_slug}}/locale/en_US/LC_MESSAGES/django.po new file mode 100644 index 00000000..6a4aa2e0 --- /dev/null +++ b/{{cookiecutter.project_slug}}/locale/en_US/LC_MESSAGES/django.po @@ -0,0 +1,12 @@ +# Translations for the {{ cookiecutter.project_name }} project +# Copyright (C) {% now 'utc', '%Y' %} {{ cookiecutter.author_name }} +# {{ cookiecutter.author_name }} <{{ cookiecutter.email }}>, {% now 'utc', '%Y' %}. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: {{ cookiecutter.version }}\n" +"Language: en-US\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" diff --git a/{{cookiecutter.project_slug}}/locale/pt_BR/LC_MESSAGES/django.po b/{{cookiecutter.project_slug}}/locale/pt_BR/LC_MESSAGES/django.po index fc17c6a6..2556abba 100644 --- a/{{cookiecutter.project_slug}}/locale/pt_BR/LC_MESSAGES/django.po +++ b/{{cookiecutter.project_slug}}/locale/pt_BR/LC_MESSAGES/django.po @@ -1,18 +1,12 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. +# Translations for the {{ cookiecutter.project_name }} project +# Copyright (C) {% now 'utc', '%Y' %} {{ cookiecutter.author_name }} +# {{ cookiecutter.author_name }} <{{ cookiecutter.email }}>, {% now 'utc', '%Y' %}. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-06-04 21:42+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" +"Project-Id-Version: {{ cookiecutter.version }}\n" +"Language: pt-BR\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n"