Honor comments for translators when extracting messages

To extract commments for translators, '--add-comments' option
must be passed to pybabel. Comments for translators were extracted
when we used Django tools to extract messages, but when we switched
to pybabel it was lost. This commit adds the option to run_tests.sh.

Move the place of existing comments for translators
so that pybabel can find them. Django tool and pybabel
expect a bit different places.
Also add comments to ungettext_lazy in test codes.

Closes-Bug: #1553581
Change-Id: Ia2df36dfebb59bede19d57b2158a907126ca1944
This commit is contained in:
Akihiro Motoki 2016-03-07 00:58:00 +09:00
parent 086b704278
commit ce6e34a5e4
4 changed files with 11 additions and 4 deletions

View File

@ -26,8 +26,8 @@ class EagerPuppiesTable(tables.DataTable):
class SellPuppy(tables.DeleteAction):
@staticmethod
def action_present(count):
# Translators: test code, don't really have to translate
return ungettext_lazy(
# Translators: test code, don't really have to translate
u"Sell Puppy",
u"Sell Puppies",
count
@ -35,8 +35,8 @@ class SellPuppy(tables.DeleteAction):
@staticmethod
def action_past(count):
# Translators: test code, don't really have to translate
return ungettext_lazy(
# Translators: test code, don't really have to translate
u"Sold Puppy",
u"Sold Puppies",
count

View File

@ -135,6 +135,7 @@ class MyBatchAction(tables.BatchAction):
@staticmethod
def action_present(count):
# Translators: test code, don't really have to translate
return ungettext_lazy(
u"Batch Item",
u"Batch Items",
@ -143,6 +144,7 @@ class MyBatchAction(tables.BatchAction):
@staticmethod
def action_past(count):
# Translators: test code, don't really have to translate
return ungettext_lazy(
u"Batched Item",
u"Batched Items",
@ -170,12 +172,14 @@ class MyToggleAction(tables.BatchAction):
def action_present(self, count):
if self.current_present_action:
# Translators: test code, don't really have to translate
return ungettext_lazy(
u"Up Item",
u"Up Items",
count
)
else:
# Translators: test code, don't really have to translate
return ungettext_lazy(
u"Down Item",
u"Down Items",
@ -184,12 +188,14 @@ class MyToggleAction(tables.BatchAction):
def action_past(self, count):
if self.current_past_action:
# Translators: test code, don't really have to translate
return ungettext_lazy(
u"Upped Item",
u"Upped Items",
count
)
else:
# Translators: test code, don't really have to translate
return ungettext_lazy(
u"Downed Item",
u"Downed Items",

View File

@ -93,9 +93,9 @@ class IndexView(tables.DataTableView):
messages.error(self.request, msg)
# gateway_info['network'] is just the network name, so putting
# in a smallish error message in the table is reasonable.
# Translators: The usage is "<UUID of ext_net> (Not Found)"
gateway_info['network'] = pgettext_lazy(
'External network not found',
# Translators: The usage is "<UUID of ext_net> (Not Found)"
u'%s (Not Found)') % ext_net_id

View File

@ -439,7 +439,8 @@ function babel_extract {
KEYWORDS+=" -k ugettext_noop -k ugettext_lazy -k ungettext_lazy:1,2"
KEYWORDS+=" -k npgettext:1c,2,3 -k pgettext_lazy:1c,2 -k npgettext_lazy:1c,2,3"
${command_wrapper} pybabel extract -F ../babel-${DOMAIN}.cfg -o locale/${DOMAIN}.pot $KEYWORDS .
${command_wrapper} pybabel extract -F ../babel-${DOMAIN}.cfg \
--add-comments Translators: -o locale/${DOMAIN}.pot $KEYWORDS .
}
function run_makemessages {