Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django doesn't create translation .po files

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?
like image 248
skazhy Avatar asked Jan 05 '11 22:01

skazhy


People also ask

How do I translate text in Django?

Use the function django. utils. translation. gettext_noop() to mark a string as a translation string without translating it.

What are .po files?

A . PO file is a portable object file, which is text-based. These types of files are used in commonly in software development. The . PO file may be referenced by Java programs, GNU gettext, or other software programs as a properties file.

What is Gettext_lazy in Django?

gettext_lazy is a callable within the django. utils. translation module of the Django project.


2 Answers

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

like image 188
jujule Avatar answered Oct 08 '22 15:10

jujule


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'

like image 20
addmoss Avatar answered Oct 08 '22 13:10

addmoss