9

We're evaluating Babel 0.9.5 [1] under Windows for use with Python 2.6 and have the following questions that we we've been unable to answer through reading the documentation or googling.

1) I would like to use an _ like abbreviation for ungettext. Is there a concencus on whether one should use n_ or N_ for this?

n_ does not appear to work. Babel does not extract text.

N_ appears to partially work. Babel extracts text like it does for gettext, but does not format for ngettext (missing plural argument and msgstr[ n ].)

2) Is there a way to set the initial msgstr fields like the following when creating a POT file?

I suspect there may be a way to do this via Babel cfg files, but I've been unable to find documentation on the Babel cfg file format.

"Project-Id-Version: PROJECT VERSION\n" "Language-Team: en_US \n"

3) Is there a way to preserve 'obsolete' msgid/msgstr's in our PO files? When I use the Babel update command, newly created obsolete strings are marked with #~ prefixes, but existing obsolete message strings get deleted.

Thanks, Malcolm

[1] http://babel.edgewall.org/

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Malcolm
  • 5,125
  • 10
  • 52
  • 75
  • Why you don't want to use just GNU gettext utilities ported to win32 for extracting the messages? http://gnuwin32.sf.net – bialix May 25 '10 at 15:02
  • 1
    Hi Bializ: Installing the GNU gettext utlities is not convenient for our customers who maintain their own PO files. Another advantage of the Babel utilities is that they work in UTF-8 mode by default. We've had some problems getting the GNU gettext utilities to do this consistently (they default to ASCIII). – Malcolm May 25 '10 at 17:49

2 Answers2

8

By default pybabel extract recognizes the following keywords: _, gettext, ngettext, ugettext, ungettext, dgettext, dngettext,N_. Use -k option to add others. N_ is often used for NULL-translations (also called deferred translations).

Update: The -k option can list arguments of function to be put in catalog. So, if you use n_ = ngettext try pybabel extract -k n_:1,2 ....

Denis Otkidach
  • 32,032
  • 8
  • 79
  • 100
  • Hi Denis: Thank you for your help. I'm aware of the -k option, but can't find a way to map N_ or n_ to the ngettext function so that these function's parameters get processed as plurals (creating msgid_plural, msgid[0], etc) vs. an alias of gettext. I appreciate the reference to the use of N_ as a NULL translation. This seems like a Python specific syntax (?) as opposed to other language gettext implementations which support N_ or n_ as ngettext aliases. – Malcolm May 25 '10 at 11:07
  • Hi Denis: Your "-k n_:1,2" technique works perfectly - thank you very much!! For the archives: We've decided to use N_ vs. n_ to follow what look likes the defacto industry standard for ngettext abbreviation. – Malcolm May 25 '10 at 17:46
1

To answer question 2):

If you run Babel via pybabel extract, you can set Project-Id-Version via the --project and --version options.

If you run Babel via setup.py extract_messages, then Project-Id-Version is taken from the distribution (project name and version in the setup.py file).

Both ways also support the options --msgid-bugs-address and --copyright-holder for setting the POT metadata.

Cito
  • 5,365
  • 28
  • 30