[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Re: I18n in koffice scripts
From:       Dag Andersen <danders () get2net ! dk>
Date:       2008-12-05 12:58:32
Message-ID: 200812051358.32912.danders () get2net ! dk
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Fredag 05 december 2008 08:29:04 Dag Andersen wrote:
>
> What to do while we wait for 4.3?
Tried out a solution for kplato (attached) to see what could actually work.
Haven't tested everyting, but translation + argument substitution seems to 
work.
In the scripts, calls would look like:
print KPlato.i18n("Text that shall be translated")
print KPlato.i18n("Text with parameters: %1 %2", ["Parameter 1", "Parameter 
2"])
etc.
This looks much like in C++, which imho is a plus. Don't know how this might 
look in other languages, though. I Only know (a little) python.

I don't know if this is difficult to extract, I'm useless on sed, awk, perl 
and you-name-it ;)

Ok, I'm off on weekend, so nothing more from me until monday. 
-- 
Mvh.
Dag Andersen

[Attachment #5 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" \
"http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" \
content="1" /><style type="text/css">p, li { white-space: pre-wrap; \
}</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; \
font-weight:400; font-style:normal;">On Fredag 05 december 2008 08:29:04 Dag Andersen \
wrote:<br> &gt;<br>
&gt; What to do while we wait for 4.3?<br>
Tried out a solution for kplato (attached) to see what could actually work.<br>
Haven't tested everyting, but translation + argument substitution seems to work.<br>
In the scripts, calls would look like:<br>
print KPlato.i18n("Text that shall be translated")<br>
print KPlato.i18n("Text with parameters: %1 %2", ["Parameter 1", "Parameter 2"])<br>
etc.<br>
This looks much like in C++, which imho is a plus. Don't know how this might look in \
other languages, though. I Only know (a little) python.<br> <p \
style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>I \
don't know if this is difficult to extract, I'm useless on sed, awk, perl and \
you-name-it ;)<br> <p style="-qt-paragraph-type:empty; margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"><br></p>Ok, I'm off on weekend, so nothing more \
                from me until monday. <br>
-- <br>
Mvh.<br>
Dag Andersen</p></body></html>


["i18n.diff" (text/x-patch)]

Index: Module.h
===================================================================
--- Module.h	(revision 892248)
+++ Module.h	(working copy)
@@ -64,6 +64,14 @@
             virtual KoDocument* doc();
             
         public Q_SLOTS:
+            /// Creates localized string from a given @p text. Substitute @p params \
(may be empty) +            QString i18n( const QString &text, const QVariantList \
&params = QVariantList() ); +            /// Creates localized string from a given @p \
text, with added context. Substitute @p params (may be empty) +            QString \
i18nc( const QString &context, const QString &text, const QVariantList &params = \
QVariantList() ); +            /// Creates localized string from a given @p plural \
and @p singular form. Substitute @p params (may be empty) +            QString i18np( \
const QString &singular, const QString &plural, const QVariantList &params = \
QVariantList() ); +            /// Creates localized string from a given @p plural \
and @p singular form, with added context. Substitute @p params (may be empty) +       \
QString i18ncp( const QString &context, const QString &text, const QVariantList \
&params = QVariantList() );  
             /// Open another KPlato document
             QObject *openDocument( const QString tag, const QString &url );
Index: Module.cpp
===================================================================
--- Module.cpp	(revision 892248)
+++ Module.cpp	(working copy)
@@ -27,12 +27,13 @@
 #include "ResourceGroup.h"
 #include "Schedule.h"
 #include "ScriptingWidgets.h"
-
 // qt
 #include <QPointer>
 #include <QWidget>
 #include <QMap>
 // kde
+#include <klocale.h>
+#include <klocalizedstring.h>
 #include <kdebug.h>
 // kplato
 #include <kptpart.h>
@@ -74,6 +75,56 @@
     delete d;
 }
 
+QString Module::i18n( const QString &text, const QVariantList &params )
+{
+    kDebug()<<text<<params;
+    KLocalizedString ls = ki18n(text.toUtf8());
+    for ( int i = 0; i < params.count(); ++i ) {
+        ls = ls.subs(params[i].toString());
+    }
+    return ls.toString();
+}
+
+QString Module::i18n( const QString &text, const QVariantList &params )
+{
+    kDebug()<<text<<params;
+    KLocalizedString ls = ki18n(text.toUtf8());
+    for ( int i = 0; i < params.count(); ++i ) {
+        ls = ls.subs(params[i].toString());
+    }
+    return ls.toString();
+}
+
+QString Module::i18nc( const QString &context, const QString &text, const \
QVariantList &params ) +{
+    kDebug()<<text<<params;
+    KLocalizedString ls = ki18n(context.toUtf8(), text.toUtf8());
+    for ( int i = 0; i < params.count(); ++i ) {
+        ls = ls.subs(params[i].toString());
+    }
+    return ls.toString();
+}
+
+QString Module::i18np( const QString &singular, const QString &plural, const \
QVariantList &params ) +{
+    kDebug()<<text<<params;
+    KLocalizedString ls = ki18n(singular.toUtf8(), plural.toUtf8());
+    for ( int i = 0; i < params.count(); ++i ) {
+        ls = ls.subs(params[i].toString());
+    }
+    return ls.toString();
+}
+
+QString Module::i18ncp( const QString &singular, const QString &plural, const \
QVariantList &params ) +{
+    kDebug()<<text<<params;
+    KLocalizedString ls = ki18n(context.toUtf8(), singular.toUtf8(), \
plural.toUtf8()); +    for ( int i = 0; i < params.count(); ++i ) {
+        ls = ls.subs(params[i].toString());
+    }
+    return ls.toString();
+}
+
 KPlato::Part* Module::part()
 {
     if(! d->doc) {



_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic