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

Stephen Kelly steveire at gmail.com
Sun Jan 23 20:00:55 GMT 2011



> On Jan. 23, 2011, 4:56 p.m., Chusslove Illich wrote:
> >

Thanks for the review!


> 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.)
> >

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


> On Jan. 23, 2011, 4:56 p.m., Chusslove Illich wrote:
> > /home/kde-devel/kdesvn/trunk/KDE/kdesdk/scripts/grantlee_strings_extractor.py, line 358
> > <http://svn.reviewboard.kde.org/r/6405/diff/2/?file=44441#file44441line358>
> >
> >     Is it guaranteed that the order of messages in the output file is exactly the same as the order in the template file?

Yes.

Additionally, the output file contains the concatenated results from multiple output files. I'm not certain if this is relevant to the question.


> On Jan. 23, 2011, 4:56 p.m., Chusslove Illich wrote:
> > /home/kde-devel/kdesvn/trunk/KDE/kdesdk/scripts/grantlee_strings_extractor.py, line 368
> > <http://svn.reviewboard.kde.org/r/6405/diff/2/?file=44441#file44441line368>
> >
> >     The line number in the template file should also be recorded for each extracted message, so that this comment can be
> >     
> >     // i18n: file: <filename>:<line>
> >

Oops, Pino mentioned this too but I forgot to do it.

Updated now.


> On Jan. 23, 2011, 4:56 p.m., Chusslove Illich wrote:
> > /home/kde-devel/kdesvn/trunk/KDE/kdesdk/scripts/grantlee_strings_extractor.py, line 386
> > <http://svn.reviewboard.kde.org/r/6405/diff/2/?file=44441#file44441line386>
> >
> >     This means that first the shell will glob the arguments, and then the script will glob for the second time? Now that's weird :)

Good point. I was assuming I had to do the globbing myself. Fixed now.


- Stephen


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


On Jan. 23, 2011, 1:24 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, 1:24 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/20110123/716bcd83/attachment.htm>


More information about the kde-core-devel mailing list