Aller au contenu. | Aller à la navigation

Outils personnels

Navigation

Vous êtes ici : Accueil / Articles / Please don't put mo files in subversion

Please don't put mo files in subversion

Par Vincent Fretin publié 07/10/2009 09:12, Dernière modification 28/02/2011 10:46
Please don't commit mo files to subversion. I show you a problem that can occur if you do that. Then I explain how you can include mo files in your package at release time.

Please don't commit mo files to subversion. Why?

  • Because it's simply noise on subversion. - Files that can be generated should not be put in subversion. - mo files can be not up to date in subversion

PlacelessTranslationService (for Plone < 4) or zope.i18n (Plone 4) takes care of regenerating the mo file if po file modification date is greater than mo file modification date. To enable autogenerating mo files in Plone 4, you have to configure your buildout like this:

    [instance]
    environment-vars =
        zope_i18n_compile_mo_files true

I will show you an example of problem.

In z3c.form 2.1.0, the "Remove selected" string is translated into French if you look at the po file, but the translation doesn't show up on the page. Why?

Because there is a mo file next to the po file and it was not up to date when the release was made.

The problem in this case is that both po and mo file have the same modification date, the extracted date actually. So the mo file will not be regenerated.

You may want to include mo files in your released package because of permission issue: the user running the zope instance doesn't have write permission to the package directory. If you want to do that, generate mo files before you do the release.

I did something like that for plone.app.locales 3.3.4:

  • Create a MANIFEST.in file next to setup.py with the following content:
        global-include *.mo
    
  • Before releasing, in the checkout tag, generate the mo files like this:
        for po in `find . -name "*.po"` ; do msgfmt -o `dirname $po`/`basename $po .po`.mo $po; done
    
      You need the *gettext* package to have the *msgfmt* command on Ubuntu.
    
  • Release as usual.

To be sure you will not commit mo files anymore, you can configure your ~/.subversion/config file like this:

    [miscellany]
    global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store *.pyc *.pyo .installed.cfg bin var parts downloads *.swp develop-eggs fake-eggs eggs archgenxml.log *.egg-info *.mo build dist .mr.developer.cfg