[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Review Request: Add extraction scripts for translatable strings
From: "Chusslove Illich" <caslav.ilic () gmx ! net>
Date: 2011-01-24 8:22:40
Message-ID: 20110124082240.24735.38823 () vidsolbach ! de
[Download RAW message or body]
> 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
>
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.)
- 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
>
>
[Attachment #3 (text/html)]
<html>
<body>
<div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
<table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 \
solid;"> <tr>
<td>
This is an automatically generated e-mail. To reply, visit:
<a href="http://svn.reviewboard.kde.org/r/6405/">http://svn.reviewboard.kde.org/r/6405/</a>
</td>
</tr>
</table>
<br />
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;"> <p style="margin-top: 0;">On January 23rd, 2011, 4:56 p.m., <b>Chusslove \
Illich</b> wrote:</p> <blockquote style="margin-left: 1em; border-left: 2px solid \
#d0d0d0; padding-left: 10px;">
<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;"> <thead>
<tr>
<th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;"> <a \
href="http://svn.reviewboard.kde.org/r/6405/diff/2/?file=44441#file44441line107" \
style="color: black; font-weight: bold; text-decoration: \
underline;">/home/kde-devel/kdesvn/trunk/KDE/kdesdk/scripts/grantlee_strings_extractor.py</a>
<span style="font-weight: normal;">
(Diff revision 2)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th> <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td> <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">107</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="c"># This is a {{ _("translatable string") }} in the \
template.</span></pre></td> </tr>
</tbody>
</table>
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">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.) </pre>
</blockquote>
<p>On January 23rd, 2011, 7:44 p.m., <b>Stephen Kelly</b> wrote:</p>
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;"> <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">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
</pre>
</blockquote>
</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">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.)</pre> <br />
<p>- Chusslove</p>
<br />
<p>On January 23rd, 2011, 8:01 p.m., Stephen Kelly wrote:</p>
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" \
style="background-image: \
url('http://svn.reviewboard.kde.orgrb/images/review_request_box_top_bg.png'); \
background-position: left top; background-repeat: repeat-x; border: 1px black \
solid;"> <tr>
<td>
<div>Review request for kdelibs, Pino Toscano and Chusslove Illich.</div>
<div>By Stephen Kelly.</div>
<p style="color: grey;"><i>Updated Jan. 23, 2011, 8:01 p.m.</i></p>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: \
1px solid #b8b5a0"> <tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">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</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: \
1px solid #b8b5a0"> <tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">Works locally. The code in playground/pim/contacts can be used to test \
this with x-test once it's checked in.</pre> </td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">
<li>/home/kde-devel/kdesvn/trunk/KDE/kdesdk/scripts/grantlee_strings_extractor.py \
<span style="color: grey">(PRE-CREATION)</span></li>
</ul>
<p><a href="http://svn.reviewboard.kde.org/r/6405/diff/" style="margin-left: \
3em;">View Diff</a></p>
</td>
</tr>
</table>
</div>
</body>
</html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic