[ZBX-4402] Gettext. Translation. Usage of context function. Created: 2011 Nov 29  Updated: 2017 May 30  Resolved: 2012 May 11

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Frontend (F)
Affects Version/s: 1.9.8 (beta)
Fix Version/s: 2.0.0rc4

Type: Incident report Priority: Major
Reporter: Oleksii Zagorskyi Assignee: Unassigned
Resolution: Fixed Votes: 1
Labels: context, gettext, translation
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File 1. pootle.png     PNG File 2. virtaal.png     PNG File 3. lokalize.png     PNG File 4. poedit.png     File context1.diff    
Issue Links:
Duplicate
is duplicated by ZBXNEXT-790 Clean up Zabbix front-end to make use... Closed

 Description   

I decided to do the experiments and select the best style to write translatable strings in context with/without comments.

Tested:
1. Pootle
2. Virtaal
3. Lokalize
4. Poedit
See attached pictures.

Considered two different styles of source code.
a) on top of the pictures:
// GETTEXT: button for switch pages
$pagespan = new CSpan('<< '._x('First', 'page'), 'darklink');

b) bottom of the picture:
$pagespan = new CSpan(_x('Last', 'context: page').' >>', 'darklink');

In the case a) I used short context definition ('page') and the comment for gettext.
In the case b) I used more complex context definition ('context: page') without the comment for gettext.

We need to discuss and select the best style regarding to save source code clear and to give for translators as much help as possible.

My personal conclusion:

  • usage only context is not enough in most cases, so need to use comments too where context is used. But it's not hard rule, it's recommendation.
  • usage the fixed part "context: " as prefix for all context strings helps to read source code and to use all mentioned tools tor translation.

So I propose the style:
// GETTEXT: button for switch pages
$pagespan = new CSpan('< '._x('Previous', 'context: page'), 'darklink');

See corresponding attached picture.

According to the "best style" a patch prepared.
Next patches will be prepared after approving current style or select another.

Documentation will be updated:
http://www.zabbix.com/documentation/2.0/contrib/frontend_localisation#code_conventions

p.s. some bad comment was fixed in the patch:
The comment format of "// GETTEXT: r is date format string as described in http://php.net/date"
was changed to "/* */" because this comment really was used for the word "Updated" but not for the word "r"



 Comments   
Comment by Oleksii Zagorskyi [ 2012 Apr 27 ]

The major application which should be taken into account first of all it's Pootle.

A minor disadvantage of usage gettext comments "// GETTEXT:" (for Pootle) that it will replace information about source code where this string is used (see previously attached picture).
The same for Virtal.

So, I agree that would be better to avoid use the context && gettext-comment in the same time.
But if optimally-short context cannot be enough self descriptive, then gettext comment is allowed to use.

Very short context (one word) also is not very good: less clear and less noticeable in the translation tool. Recommended length is 2-3 words.
It's recommended to not use any punctuation for context string.

For that example (in issue summary) the code would be:
$pagespan = new CSpan('< '._x('Previous', 'page navigation'), 'darklink');

Opinions?

Comment by Oleksii Zagorskyi [ 2012 Apr 27 ]

Note to devs:

code lines:
$this->addRow(('Updated').': '.zbx_date2str(('r'), time())); // GETTEXT: r is date format string as described in http://php.net/date
$this->addRow(_('Users (online)').': '.$status['users_count'].'('.$status['users_online'].')');

in the "frontend.po" visible like this:

#. GETTEXT: r is date format string as described in http://php.net/date
#: include/classes/class.cserverinfo.php:44
msgid "Users (online)"
msgstr "Пользователи (подключены в данный момент)"

Note that that comment applied to the "Users (online)" string.
It's wrong !
Here you can see how is it bad (before applying a patch) : https://www.zabbix.org/pootle/ru/Zabbix-2.0/translate.html?unit=93460

See doc: http://www.zabbix.com/documentation/2.0/contrib/frontend_localisation#comments_for_translators

It will be fixed in next suggested patch.
That gettext note removed and 'r' replaced to translatable 100% identical form 'D, d M Y H:i:s O'

Comment by Oleksii Zagorskyi [ 2012 Apr 28 ]

New patch (according rules described above) attached.
Please review it, merge to SVN and regenerate in Pootle.

Comment by Alexey Fukalov [ 2012 May 03 ]

dev branch: svn://svn.zabbix.com/branches/dev/ZBX-4402
File en_gb.php is removed in this branch too.

Comment by Oleksii Zagorskyi [ 2012 May 03 ]

Dev branch successfully tested.
PHP version 5.4.1 rc1

Comment by Oleksii Zagorskyi [ 2012 May 03 ]

(1)
"May" it's the same for short and for full version. but Ukrainian full version of May has 7 letters (Травень)
The same for cs_cz, hu_hu, lv_lv, pt_br, sk_sk. See http://pastebin.com/eRAfmtn0
Probably would be better to add context to only one month "May"

See func.inc.php#201 to add context

  • 5 => _('May'),
    + 5 => _x('May', 'May short'),

<Vedmak> RESOLVED

<zalex> It's correct solution and can be CLOSED, but here is some issue. Se regenerated Ukrainian PO file part:

#: include/forms.inc.php:1538 include/func.inc.php:110
#: include/func.inc.php:239 jsLoader.php:110
msgid "May"
msgstr "Тра"

#: include/func.inc.php:222
msgctxt "May short"
msgid "May"
msgstr ""

As we see "Тра" (short version) stayed linked to the sting "May" (full version, without context)

Rich, maybe this string somehow can be removed from PO files before synchronization with Pootle ?
Then translators will translate it once again and correctly.

<richlv> yes, you could add that as another sub-problem comment here

<zalex> CLOSED

Comment by Oleksii Zagorskyi [ 2012 May 03 ]

(2) -> to Rich
Before synchronization with Pootle remove one string - see comments above.
Maybe not for all languages, but only for listed above.

Comment by Oleksii Zagorskyi [ 2012 May 03 ]

(3) [Documentation] -> to Oleksiy
Guidelines will be added here: http://www.zabbix.com/documentation/2.0/contrib/frontend_localisation#code_conventions

<zalex> RESOLVED
<martins-v> CLOSED

Comment by Oleksii Zagorskyi [ 2012 May 04 ]

It seems ZBXNEXT-790 can be closed after this one.

Comment by Pavels Jelisejevs (Inactive) [ 2012 May 07 ]

Just a thought: wouldn't it be better to make more general contexts instead of a lot of small ones? E.g: "units short" instead of "micro short", "mega short" etc. I also don't like that these contexts are literal strings: if we'll need to change them, we'll have to do a hell lot of editing and the cool autocomplete features won't be available.

<zalex> I'm sure that "micro short" and "mega short" are better than "units short" because they also explain what they are (mega, micro, etc).
Additional example:
+ 'S_TUESDAY_SHORT_BIG'=> _x('T', 'Tuesday short'),
+ 'S_THURSDAY_SHORT_BIG'=> _x('T', 'Thursday short'),
I did not understand second question, sorry. I believe in most cases where context should be added it has been added already, in the future I expect very-very small count of strings which should be changed to use the context.

<pavels> The only benefit I see from using more general contexts, is that they will be easier to document and follow, i.e. if I need to add a context string for "Mon", I would first check, if some short-day-related context already exists to be consistent with other translations. But that's just a thought, if you think that your approach is better, I'll trust you =).

Forget the second question, it couldn't be done anyway: I missed one thing when I wrote it.

<zalex> I see, it sounds logically, but as I said, I suppose we already have implemented almost all places where context should be used. So it almost unreal that it will worth to use more general context to avoid potential extra work for translators.
We use context to not split "domains" of terms/sentences which can have different meaning, but to split short words which translated differently in other languages.
I suppose it's CLOSED.

Comment by Pavels Jelisejevs (Inactive) [ 2012 May 07 ]

(4) We might as well remove the would-be constants from JS files.

<pavels> Discussed it with vedmak: we can't right now. CLOSED.

Comment by Toms (Inactive) [ 2012 May 07 ]

(5) class.cserverinfo.php:43 "D, d M Y H:i:s O" could be used as constant, same in CXmlImport18.php:303&304

<Vedmak> RESOLVED

<Toms> CLOSED

Comment by Toms (Inactive) [ 2012 May 07 ]

(6) CCanvas.php:73 home page also could be used as constant

<Vedmak> RESOLVED

<Toms> CLOSED

Comment by Toms (Inactive) [ 2012 May 07 ]

(7) jsLoader.php missing GNU licence

<Vedmak> hmm, i have licence in that file.

<Toms> Mistaken something. CLOSED

Comment by Toms (Inactive) [ 2012 May 07 ]

(8) "May short" could be written as "month May short", it would be easier to understand.

<Vedmak> I think it's not needed, as then it will be inconsistent with other months and capital letter gives the hint that it's month.

<Toms> CLOSED

Comment by Oleksii Zagorskyi [ 2012 May 07 ]

(9) [minor] Consider please to add contex to "Y":
// GETTEXT: Date format (year). Do not translate.
define('REPORT4_ANNUALLY_DATE_FORMAT', _('Y'));

because "Y" is very short word, and maybe would be better to add context from very begging, just in case.
And please leave the GETTEXT comment.

<Vedmak> RESOLVED

<zalex> Thanks, I'd say CLOSED

Comment by Toms (Inactive) [ 2012 May 08 ]

TESTED

Comment by Alexey Fukalov [ 2012 May 08 ]

svn://svn.zabbix.com/trunk 27340

Comment by Alexey Pustovalov [ 2012 May 08 ]

#: events.php:479 include/actions.inc.php:71
#: include/views/configuration.services.child.list.php:36
#: include/views/configuration.services.edit.php:257
#: include/views/configuration.services.parent.list.php:36 services.php:430
#: srv_status.php:258
Service
the translation is different for Ru and Uk languages for IT Services and Discovery features.

<zalex> moved to ZBX-4988.
CLOSED

Comment by Oleksii Zagorskyi [ 2012 May 11 ]

Reopened to perform some service.

Comment by Oleksii Zagorskyi [ 2012 May 11 ]

Closed again

Generated at Sat Apr 20 16:06:21 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.