Page MenuHomePhabricator

Add translator comments to all strings for translation
Closed, ResolvedPublic

Description

From T162479:

So if you take a look at:
https://github.com/WikipediaLibrary/TWLight/blob/master/locale/qqq/LC_MESSAGES/django.po
You'll see that line 28 has a translator note on it. We need to add translation notes in there for every message. The notes get into that file by being picked up in the bit of code referenced in the comment. eg.

#. Translators: This labels a section of a form where we ask users to enter info (like country of residence) when applying for resource access.
#: TWLight/applications/forms.py:189
msgid "About you"
msgstr ""

There's a tranlator note in TWLight/applications/forms.py just ahead of the message label on line 189, that our tooling was able to pick up and place in this document. We'll need to add useful translation notes as Translators: comments in the source code. Basically, you'd need to fork the codebase on github, and start backtracing the referenced code bits in django.po and adding comments.

Event Timeline

Pro tip:
If you start adding comments to the source code. Work your way from bottom to top rather than top to bottom.
Adding comments will change the line counts of everything under it and make the references in the django.po much less useful.

Quick question - if there are multiple code lines above the string do I only need to comment at one of them, or all?

Also, do I need to update the line numbers in django.po, or is it automatically updated?

Also also, in the case that some code is like this:

partner_layout = Fieldset(
    _('Your application to {partner}').format(partner=partner_object))

I assume it's fine to put the comment like so?

#Comment goes here?
partner_layout = Fieldset(
    _('Your application to {partner}').format(partner=partner_object))

EDIT: Nevermind, I've seen it needs to go right above, per an example elsewhere in the code.

Another question: If a string contains variables, e.g.

Reviewed on {{ review_date }}

do I need to point out in the comment that everything in the squigglys doesn't need translating?

@Samwalton9 let's start out by just commenting the first bit of source code listed that contains a comment. When we've got the code commented up, I'll regenerate django.po and it will have proper line numbers. Make sure to start your comments with

# Translators:

You are correct that we should make note of variables and other markup that shouldn't be translated. Here's a yaml example of message documentation that has the kind of notes we need to have
https://github.com/lonvia/waymarked-trails-site/blob/master/django/locale/qqq/helppages.yaml

And you can always reference the translate wiki notes on it:
https://translatewiki.net/wiki/Translating:Localisation_for_developers#Message_documentation

Thanks!

Where should the comment go in a block like this?

<p>
  {% blocktrans trimmed %}
    Comments are visible to all
    coordinators and to the editor who submitted this application.
  {% endblocktrans %}
</p>

And where is the information in TWLight/applications/templates/applications/application_list_include.html seen on the site? I'm struggling to find it.

More questions!

If I have the line

[_('Month'), _('Median days until decision')])

with each string being a separate entry in django.po, do you know where I put the comment for each? One above the other directly above? Or should I split the line like:

#Comment
[_('Month'),
#Comment 2
 _('Median days until decision')])

The bit with the html markup looks like a template file, which is a jijna template. Jinja comments can be done like:

{% comment %}
  Tranlators: 
{% endcomment %}

I believe
TWLight/applications/templates/applications/application_list_include.html
gets pulled into the editor detail page (like when you click your own username while logged in)

On this last one:
You should be using the django.po file as the starting point for working your way back into the codebase. django.po contains all the translatable messages, and the messages in there are exactly what the translators will see. It it's a single message in the po file, then the comments need to treat it that way.

In django.po that last one shows as:

#: TWLight/graphs/views.py:266
msgid "Month"
msgstr ""

#: TWLight/graphs/views.py:266
msgid "Median days until decision"
msgstr ""

Looking at another example of this, line 249 of the same file:

# Translators: This is the heading of a data file which lists the number of days it took to decide on applications that have already been accepted/rejected.
[_('Days until decision'), _('Number of applications')])

And the corresponding lines in django.po:

#. Translators: the number of days it took to decide on applications that have already been accepted/rejected.
#: TWLight/graphs/views.py:249
msgid "Days until decision"
msgstr ""

#: TWLight/graphs/views.py:249 TWLight/graphs/views.py:283
msgid "Number of applications"
msgstr ""

It seems like the comment is only picked up for the first string. Is splitting the code line like in my previous comment the right way to add a comment to each?

and I reread your last question more carefully: yes, probably splitting it is best. When you break up a list, you should indent like so:

urlpatterns = [
    url(r'^$',
        views.PartnersListView.as_view(),
        name='list'
    ),
    url(r'^(?P<pk>\d+)/$',
        views.PartnersDetailView.as_view(),
        name='detail'
    ),
    url(r'^toggle_waitlist/(?P<pk>\d+)/$',
        views.PartnersToggleWaitlistView.as_view(),
        name='toggle_waitlist'
    ),
]

Comments should be the exact same indention as the thing directly below them

New question!

#: TWLight/resources/models.py:320
msgid ""
"The form of the contact person's name to use in email greetings (as in 'Hi "
"Jake')"

For split strings like this do I need to include instruction to keep the formatting the same? Or should we really make it one full string?

And another - how do I fit the comment for "download as csv" in for this line?

<h3>{% trans "Applications by status" %} <a href="{% url 'csv:app_distribution_by_partner' object.pk %}" class="pull-right btn btn-default">{% trans "download as csv" %}</a></h3>

I assume I need to split the line again but I'm less confident about this code's behaviour in regards to line splitting.

Pull request submitted, with file attached flagging the strings I haven't done.