Django doesn't create translation .po files
Asked Answered
H

3

12

I have my translation strings only in templates (stored in the project_dir/Templates), I tried running the $ django-admin.py createmessages -l ru both in the project root directory and in the app directories that use templates with trans. strings. It created folders locale/ru/LC_MESSAGES but the folders were empty. I tried to add the django.po files manually (with the syntax mentioned in the l10n docs). And ran the createmessages -a and compilemessages commands. It created the .mo files, but the translations didn't appear in the browser.

  1. As I created the .po files manually I had no lines starting with #. What should I write there?
  2. My template files are in different folder than the .py files for apps. Should I put some extra links to them?
Hurtful answered 5/1, 2011 at 22:11 Comment(3)
Have you checked that django has not set the lazy tag to the translations? Paste a fragment of your .po file to see what you have.Vedavedalia
The .po files that I created were pairs of msgids and msgstrs where msgid corresponds to a {% trans %} in a template.Hurtful
Is your LOCALE_PATHS set in settings?Crescentic
L
24

did you try :

python manage.py makemessages -a 

from project root and app ?

this should create a .po that you have to edit. be sure to remove 'fuzzy' stuff everywhere.

then :

python manage.py compilemessages

You need to restart the server

Larrigan answered 6/1, 2011 at 0:16 Comment(4)
It does not create the .po files. It just shows processing language ru and that's it :(Hurtful
weird. do you have gettext installed ? Also the templates must be loadable with settings.TEMPLATE_LOADERS to be detected. Also try adding a call to django.utils.translation.gettext in a .py file to see if it comes from the templates or not.Larrigan
what does "remove fuzzy stuff everywhere" mean exactly?Myra
After makemessages, the tools may mark some entries as fuzzy. These are strings that are similar but not exactly equal to other existing strings. This may happen ie if a string was modified slightly. Then makemessages will mark those for reviewal, and Django won't show those entries until the fuzzy flag has been removed.Miru
H
1

For newer versions of Django (e.g. 3.2):

  1. in the root directory create folder "locale"

  2. run command django-admin makemessages -l ru

  3. update your language files (located in the locale folder)

  4. run django-admin compilemessages

  5. Configure the LOCALE_PATHS in settings.py, otherwise you won't see the translations:

    LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]

    LANGUAGE_CODE = 'ru'

Hilaria answered 25/4, 2021 at 7:3 Comment(0)
C
0

To fix empty po files:

  1. Make sure you did the needed changes for the templates as mentioned in the documentation. Please make sure that you are checking the correct documentation version for your project.
  2. You can add a locale directory in your templates directory and add its path to the LOCALE_PATHS list. (Optional, but helpful to make sure that the template directory is included in step 4)
  3. Go to the project_dir (you should run the next command in a parent directory of the files to be translated)
  4. Run the command django-admin makemessages -l ru
Conidiophore answered 27/4, 2021 at 13:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.