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

List:       kde-core-devel
Subject:    Re: Helping libraries load their own translation catalogs
From:       Albert Astals Cid <aacid () kde ! org>
Date:       2010-11-28 19:39:41
Message-ID: 201011281939.41478.aacid () kde ! org
[Download RAW message or body]

A Diumenge, 28 de novembre de 2010, Ivan Cukic va escriure:
> On Monday, 22. November 2010. 19.05.45 Albert Astals Cid wrote:
> > A Dilluns, 22 de novembre de 2010, David Faure va escriure:
> > > On Sunday 21 November 2010, Oswald Buddenhagen wrote:
> > > > On Sun, Nov 21, 2010 at 12:46:53AM +0000, Albert Astals Cid wrote:
> > > > > It achieves that by creating a static that instructs KGlobal to
> > > > > load a given translation catalog on global locale creation.
> 
> Just to note that this fails for catalogs that have a dash in their name

Wops, that's too bad.

Unless someone with more knowledge than me is able to fix my macro i'm 
suggesting the attached patch.

It breaks current users of K_CATALOG_LOADER, but according lxr.kde.org there 
is none at the moment so it's not a big deal i guess :D

Comments?

Albert

> 
> 
> Cheerio

["kcatalogloader.patch" (text/x-patch)]

Index: kernel/kglobal.cpp
===================================================================
--- kernel/kglobal.cpp	(revision 1201792)
+++ kernel/kglobal.cpp	(working copy)
@@ -118,6 +118,12 @@
         }
 };
 
+KCatalogLoader::KCatalogLoader(const QString &catalogName)
+{
+    KGlobal::insertCatalog(catalogName);
+}
+
+
 K_GLOBAL_STATIC(KGlobalPrivate, globalData)
 K_GLOBAL_STATIC_WITH_ARGS(KComponentData, fakeComponent, (KGlobalPrivate::initFakeComponent()))
 
Index: kernel/kglobal.h
===================================================================
--- kernel/kglobal.h	(revision 1201792)
+++ kernel/kglobal.h	(working copy)
@@ -300,31 +300,26 @@
 } NAME;
 
 /**
- * This macro is useful in libraries where you want to make sure that
+ * This class is useful in libraries where you want to make sure that
  * anyone that uses your library will get the correct catalog loaded.
+ * Just declare a static KCatalogLoader in the global namespace of one of
+ * your cpp files and that will load your catalog once
+ * the global klocale is created
  *
- * @param CATALOGNAME The name of your catalog
+ * @param catalogName The name of your catalog
  *
  * @since 4.6
  *
  * Example:
  * @code
- * K_CATALOG_LOADER(libkdepim)
+ * static const KCatalogLoader loader("libkdepim");
  * @endcode
- * 
- * @ingroup KDEMacros
  */
-#define K_CATALOG_LOADER(CATALOGNAME)                               \
-class KCatalogLoader##CATALOGNAME                                   \
-{                                                                   \
-    public:                                                         \
-        KCatalogLoader##CATALOGNAME();                              \
-};                                                                  \
-static KCatalogLoader##CATALOGNAME catalogLoader##CATALOGNAME;      \
-KCatalogLoader##CATALOGNAME::KCatalogLoader##CATALOGNAME()          \
-{                                                                   \
-    KGlobal::insertCatalog(QLatin1String(#CATALOGNAME));            \
-}
+class KCatalogLoader
+{
+    public:
+        KCatalogLoader(const QString &catalogName);
+};
 
 /**
  * Access to the KDE global objects.


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

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