i18n infrastructure for Grantlee templates

Stephen Kelly steveire at gmail.com
Thu Jan 20 23:29:45 GMT 2011


I'm ready to release the next version of Grantlee, which is the first 
version with i18n features. The aim is to mark strings as translatable 
inside the template files instead of in C++.

Before I release it I'd like to make sure it can fit into the KDE i18n 
infrastructure. The test case for that is very small - KJots has only one 
translatable string appearing in a template. 

Here's the patch I'd like to apply to kdepim:

diff --git a/kjots/Messages.sh b/kjots/Messages.sh
index 9c04534..8b6704e 100644
--- a/kjots/Messages.sh
+++ b/kjots/Messages.sh                                                                                                              
@@ -1,3 +1,4 @@
 #! /bin/sh
 $EXTRACTRC *.rc *.ui *.kcfg >> rc.cpp
+$EXTRACT_TEMPLATE_STRINGS ts.cpp themes/default/*.html
 $XGETTEXT *.cpp -o $podir/kjots.pot
diff --git a/kjots/kjotswidget.cpp b/kjots/kjotswidget.cpp
index cba22d2..3355a3b 100644
--- a/kjots/kjotswidget.cpp
+++ b/kjots/kjotswidget.cpp
@@ -884,8 +884,6 @@ QString KJotsWidget::renderSelectionToHtml()
   hash.insert( QLatin1String( "entities" ), objectList);
-  hash.insert( QLatin1String( "i18n_TABLE_OF_CONTENTS" ),
-              i18nc("Header for 'Table of contents' section of rendered 
output", "Table of contents") );
   Context c(hash);
   Template t = m_templateEngine->loadByName( QLatin1String( "template.html" 
) );
diff --git a/kjots/themes/default/booktemplate.html 
index f3e900b..4929509 100644
--- a/kjots/themes/default/booktemplate.html
+++ b/kjots/themes/default/booktemplate.html
@@ -1,7 +1,8 @@
 <h2><a href="#book_{{ entity.entityId }}" name="book_{{ entity.entityId 
}}">{{ entity.title }}</a></h2>
-<h3>{{ i18n_TABLE_OF_CONTENTS }}</h3>
+<h3>{% i18nc "Header for 'Table of contents' section of rendered output" 
"Table of contents" %}</h3>
 <div class="toc">
 {% include "book_toc_list.html" %}

The line

+$EXTRACT_TEMPLATE_STRINGS ts.cpp themes/default/*.html

assumes the existence of a script to extract the translatable string with 
context from the template

{% i18nc "Header for 'Table of contents' section of rendered output" "Table 
of contents" %}

All .html files in themes/default/ are searched for translatable strings and 
all extracted strings are put into ts.cpp, which xgettext then uses to 
create kjots.pot.

The $EXTRACT_TEMPLATE_STRINGS is already written, so I'd be asking to put 
the relevant files somewhere scripty can use them, and update scripty to 
populate the $EXTRACT_TEMPLATE_STRINGS variable.


Will that be a problem? Can I coordinate that with someone?

All the best,


More information about the kde-core-devel mailing list