Review Request: Add extraction scripts for translatable strings from Grantlee templates

Chusslove Illich caslav.ilic at gmx.net
Mon Jan 24 08:43:30 GMT 2011



> On Jan. 23, 2011, 4:56 p.m., Chusslove Illich wrote:
> > /home/kde-devel/kdesvn/trunk/KDE/kdesdk/scripts/grantlee_strings_extractor.py, line 107
> > <http://svn.reviewboard.kde.org/r/6405/diff/2/?file=44441#file44441line107>
> >
> >     What is the difference between _() and i18n()? The example shows one to be ordinary text and the other having a placeholder, but they should be synonyms. 
> >     
> >     Since _() is native Gettext convention, other synonyms in the same vein would be p_() for i18nc(), n_() for i18np(), and pn_() for i18ncp().
> >     
> >     (Just to be sure, are translations fetched later really through KDE i18n calls? Only then should calls have i18n*() names.)
> >
> 
> Stephen Kelly wrote:
>     Well, there is no i18n() function in the template system. The _() syntax is not really a function call, but just a syntactic marker indicating that the string should be extracted and run through the translation system. The _() syntax can also not take any arguments, so it is always ordinary text and can't handle placeholders. This is similar in semantics to how the django template system works. 
>     
>     {{ _("translatable string") }}
>     
>     is a shortcut for the 'template tag'
>     
>     {% i18n "translatable string" %}
>     
>     Not the use of {{ }} in one case and {% %} in the other. These are the two types of parsable tokens in the syntax. {{ }} is simple value substitution and {% %} can be anything, like value substitution in the i18n case, or more complexity in the case of the 'if' tag:
>     
>     {% if something %}It's true{% else %}It's false{% endif %}
>     
>     Arguments to tags are separated by whitespace, so as you noticed we can have 
>     
>     {% i18n "The time is %1" the_time %}
>     
>     But we can't do the same with _().
>     
>     Because _() is not a function call that can have arguments, the additional syntaxes you proposed (which require arguments) don't really belong.
>     
>     The translations are fetched later through the use of KLocalizedString such as approximately:
>     
>     QString translateString(const QString &input, const QDateTime &arg)
>     {
>       KLocalizedString ls = ki18n(input.toLatin1());
>       ls.subs(arg);
>       return ls.toString(d->usedLocale);
>     }
>     
>     And that is called with approximately:
>     
>     QDateTime now = getNow();
>     QString result = translateString("The time is %1", now);
>     
>     I'm simplifying this of course for this example because I don't fully understand the nature of your question. I'm not certain how this affects your comment about whether the tag should be called i18n or not.
>     
>     I generated documentation for the development version and put it online. It may clarify this stuff further:
>     
>     http://grantlee.org/apidox_i18n/i18n_l10n.html
>
> 
> Chusslove Illich wrote:
>     Your explanation answers my question perfectly. The distinction between {{ }} and {% %} slipped my mind; and _() and i18n are indeed synonyms under the hood (both using KLocalizedString, with proper parameter substitution as required). Ignore my mention of p_, n_, np_.
>     
>     (A detail off topic: it should always be ki18n(someqstring.toUtf8()), in order not to needlesly constrain the original text.)
> 
> Stephen Kelly wrote:
>     Thanks. I've fixed that in the example app too.
>     
>     So is that a ship it from you?

Right, missed that.


- Chusslove


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://svn.reviewboard.kde.org/r/6405/#review9687
-----------------------------------------------------------


On Jan. 23, 2011, 8:01 p.m., Stephen Kelly wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://svn.reviewboard.kde.org/r/6405/
> -----------------------------------------------------------
> 
> (Updated Jan. 23, 2011, 8:01 p.m.)
> 
> 
> Review request for kdelibs, Pino Toscano and Chusslove Illich.
> 
> 
> Summary
> -------
> 
> The new scripts allow the kde i18n infrastructure to extract translatable strings from Grantlee templates.
> 
> An additional line is needed in the Messages.sh script
> 
> 
> Diffs
> -----
> 
>   /home/kde-devel/kdesvn/trunk/KDE/kdesdk/scripts/grantlee_strings_extractor.py PRE-CREATION 
> 
> Diff: http://svn.reviewboard.kde.org/r/6405/diff
> 
> 
> Testing
> -------
> 
> Works locally. The code in playground/pim/contacts can be used to test this with x-test once it's checked in.
> 
> 
> Thanks,
> 
> Stephen
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20110124/34c5aedc/attachment.htm>


More information about the kde-core-devel mailing list