Split up .po files for Internationalization

543 views
Skip to first unread message

Thomas M

unread,
Jun 24, 2011, 7:54:33 AM6/24/11
to Django users
Hello django users,

I want to use the django internationalization module to translate
stuff. The problem is the large .po file with all the django related
stuff the translator shouldnt see.
Is there a way to split up those .po files so we've got a file with
only our translations?

Thank you in advance,
Thomas M

Kenneth Gonsalves

unread,
Jun 24, 2011, 8:06:25 AM6/24/11
to django...@googlegroups.com
On Fri, 2011-06-24 at 04:54 -0700, Thomas M wrote:
> I want to use the django internationalization module to translate
> stuff. The problem is the large .po file with all the django related
> stuff the translator shouldnt see.
> Is there a way to split up those .po files so we've got a file with
> only our translations?

have your own local .po files - do not tell me that you are your local
stuff in django's .po files?
--
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://ilugcbe.techstud.org/

Thomas M

unread,
Jun 24, 2011, 8:43:10 AM6/24/11
to Django users
I've copied the contents of the django-site packages to my project
root.
It was explained somewhere in this tutorial:
https://docs.djangoproject.com/en/1.3/topics/i18n/localization/
so I can just create my own locale files in projectpath/locale/LANG/
LC_MASSAGES/?

like:
projectpath/locale/LANG/LC_MASSAGES/email.po
projectpath/locale/LANG/LC_MASSAGES/messages.po ??

And if i name the folder "locale" according to the tutorial, the
server crashes with the error "ImportError: cannot import name
normalize" because it looks for normalize in the created locale folder
and not the standard lib.
Can I change this somehow?
Or do you know a better documentation for this as the django one?

Thanks and regards,
Thomas M

Kenneth Gonsalves

unread,
Jun 24, 2011, 8:58:01 AM6/24/11
to django...@googlegroups.com
On Fri, 2011-06-24 at 05:43 -0700, Thomas M wrote:
> It was explained somewhere in this tutorial:
> https://docs.djangoproject.com/en/1.3/topics/i18n/localization/
> so I can just create my own locale files in projectpath/locale/LANG/
> LC_MASSAGES/?

yes - that is what the docs say
>
> like:
> projectpath/locale/LANG/LC_MASSAGES/email.po
> projectpath/locale/LANG/LC_MASSAGES/messages.po ??

better: apppath/locale/LANG/LC_MESSAGES/django.po

LC_MASSAGES is wrong, it is LC_MESSAGES

Thomas M

unread,
Jun 24, 2011, 9:20:28 AM6/24/11
to Django users
Great, putting it into the app directories worked fine and solved the
import error as well.

Thank you very much.
Thomas M

On 24 Jun., 14:58, Kenneth Gonsalves <law...@thenilgiris.com> wrote:
> On Fri, 2011-06-24 at 05:43 -0700, Thomas M wrote:
> > It was explained somewhere in this tutorial:
> >https://docs.djangoproject.com/en/1.3/topics/i18n/localization/
> > so I can just create my own locale files in projectpath/locale/LANG/
> > LC_MASSAGES/?
>
> yes - that is what the docs say
>
>
>
> > like:
> > projectpath/locale/LANG/LC_MASSAGES/email.po
> > projectpath/locale/LANG/LC_MASSAGES/messages.po ??
>
> better: apppath/locale/LANG/LC_MESSAGES/django.po
>
> LC_MASSAGES is wrong, it is LC_MESSAGES
>
> --
> regards

Gelonida

unread,
Jun 24, 2011, 10:45:11 AM6/24/11
to django...@googlegroups.com
Perhaps I'm wrong, but I thought it's enough to just create a
locale/<lang>/LC_MESSAGES/django.po file
in your project tree

and then call manage.py makemessages -s -l <lang>

Tom Evans

unread,
Jun 24, 2011, 11:01:58 AM6/24/11
to django...@googlegroups.com
On Fri, Jun 24, 2011 at 3:45 PM, Gelonida <gelo...@gmail.com> wrote:
> Perhaps I'm wrong, but I thought it's enough to just create a
> locale/<lang>/LC_MESSAGES/django.po file
> in your project tree
>
> and then call manage.py makemessages -s -l <lang>
>

You shouldn't be manually creating these files at all, django provides
tools that do that for you (and spell LC_MESSAGES correctly etc). You
simply run django-admin.py makemessages -l <lang> from the top level
of each app that is to be translated, and it correctly populates
./locale/<lang>/LC_MESSAGES/django.po with the translations that have
been marked up in that apps templates and source code.

I'd suggest a thorough re-read of the documentation if you ever find
yourself manually creating pofiles.

Cheers

Tom

Stuart MacKay

unread,
Jun 24, 2011, 11:06:30 AM6/24/11
to django...@googlegroups.com
If you split your translation strings into separate files, e.g.

locale/<lang>/LC_MESSAGES/model.po
locale/<lang>/LC_MESSAGES/forms.po

manage.py compilemessages will compile them successfully to create .mo
files BUT django (1.3) will not load them. It expects to see ONE file
called django.mo - it will not load the other mo files and if there is
no django.mo file then no translations are loaded.

A possible step would be to split the files then simply concatenate them
together, using a custom management command, before calling
compilemessages. That would make it easier to manage the translations
but at the cost of an extra step in preparing for deployment.

Stuart MacKay
Lisbon, Portugal

Herman Schistad

unread,
Jun 24, 2011, 11:26:21 AM6/24/11
to django...@googlegroups.com
On Fri, Jun 24, 2011 at 17:06, Stuart MacKay
<sma...@flagstonesoftware.com> wrote:
> A possible step would be to split the files then simply concatenate them
> together, using a custom management command, before calling compilemessages.
> That would make it easier to manage the translations but at the cost of an
> extra step in preparing for deployment.

It would though, in my opinion, be a good feature to maybe specify
which files to compile with compilemessages such that this feature was
built into django.
E.g.

$ ls
forms.po models.po translators.po
$ django-admin.py compilemessages translators.po models.po
$ ls
forms.po models.po translators.po django.mo

Or something. I'm not a django developer, but I'm sure someone here
is, and this may have been a ticket sometime? :)

--
With regards, Herman Schistad

Gelonida

unread,
Jun 24, 2011, 4:12:36 PM6/24/11
to django...@googlegroups.com
Hi Tom,


Thanks for rectifying my answer.

On 6/24/2011 5:01 PM, Tom Evans wrote:
> On Fri, Jun 24, 2011 at 3:45 PM, Gelonida<gelo...@gmail.com> wrote:
>> Perhaps I'm wrong, but I thought it's enough to just create a
>> locale/<lang>/LC_MESSAGES/django.po file
>> in your project tree
>>
>> and then call manage.py makemessages -s -l<lang>
>>
>
> You shouldn't be manually creating these files at all, django provides
> tools that do that for you (and spell LC_MESSAGES correctly etc). You
> simply run django-admin.py makemessages -l<lang> from the top level
> of each app that is to be translated, and it correctly populates
> ./locale/<lang>/LC_MESSAGES/django.po with the translations that have
> been marked up in that apps templates and source code.

Fully agree. Just started working with Django. I used makemessages as
the doc (and you) suggested.

I just forgot about it when writing this post.

Reply all
Reply to author
Forward
0 new messages