Fwd: Using multiple klocales uses stale translations

Stephen Kelly steveire at gmail.com
Sun Nov 7 15:59:16 GMT 2010


Moving to k-c-d.


--------------- Forwarded message (begin)

Subject: Using multiple klocales uses stale translations
From: Stephen Kelly <steveire at gmail.com>
Date: Sun, 07 Nov 2010 15:03:01 +0100
Newsgroup: gmane.comp.kde.devel.internationalization-and-documentation

Hi,

I'm trying to get strings from different locales, but gettext seems to be 
caching the result from the previous language.

For example, I patch kwrite like this:

$ git diff .
diff --git a/apps/kwrite/kwritemain.cpp b/apps/kwrite/kwritemain.cpp
index d8af711..6c50423 100644
--- a/apps/kwrite/kwritemain.cpp
+++ b/apps/kwrite/kwritemain.cpp
@@ -675,6 +675,15 @@ extern "C" KDE_EXPORT int kdemain(int argc, char 
**argv)
 
   KWriteApp a(args);
 
+  KLocalizedString s1 = ki18n("&New Window");
+
+  KLocale de("kwrite", "de");
+  KLocale fr("kwrite", "fr");
+
+  kDebug() << s1.toString(&de);
+  kDebug() << s1.toString(&fr);
+
+
   return a.exec ();
 }


and start it in my default locale (en_US) I get this:

kwrite(560) kdemain: "&Neues Fenster"
kwrite(560) kdemain: "&Neues Fenster"

That is, the German version twice. Swapping the toString calls I get the 
French version twice.

I get one followed by the other only if I apply this patch:

$ git diff localization/kcatalog.cpp
diff --git a/kdecore/localization/kcatalog.cpp 
b/kdecore/localization/kcatalog.cpp
index 240885e..2abc9ad 100644
--- a/kdecore/localization/kcatalog.cpp
+++ b/kdecore/localization/kcatalog.cpp
@@ -189,13 +189,10 @@ void KCatalogPrivate::setupGettextEnv ()
     //kDebug() << "bindtextdomain" << name << localeDir;
     bindtextdomain(name, localeDir);
 
-    // // Magic to make sure Gettext doesn't use stale cached translation
-    // // from previous language.
-    // extern int _nl_msg_cat_cntr;
-    // ++_nl_msg_cat_cntr;
-    //
-    // Note: Not needed, caching of translations is not an issue because
-    // language is switched only if translation is not found.
+    // Magic to make sure Gettext doesn't use stale cached translation
+    // from previous language.
+    extern int _nl_msg_cat_cntr;
+    ++_nl_msg_cat_cntr;
   }
 }
 

Clearly someone decided that should be commented out. Should what I am 
trying work already, or does that need to be uncommented?

I also noticed that when I do this:


  QDate now = QDate::currentDate();

  kDebug() << de.formatDate(now, KLocale::ShortDate);
  kDebug() << fr.formatDate(now, KLocale::ShortDate);

I always get the date in the system locale instead of de or fr. Shouldn't 
that work?

All the best,

Steve.



--------------- Forwarded message (end)






More information about the kde-core-devel mailing list