From kde-core-devel Sun Nov 28 19:39:41 2010 From: Albert Astals Cid Date: Sun, 28 Nov 2010 19:39:41 +0000 To: kde-core-devel Subject: Re: Helping libraries load their own translation catalogs Message-Id: <201011281939.41478.aacid () kde ! org> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=129097324732473 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_9/q8McJiRf39g73" --Boundary-00=_9/q8McJiRf39g73 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 --Boundary-00=_9/q8McJiRf39g73 Content-Type: text/x-patch; charset="UTF-8"; name="kcatalogloader.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kcatalogloader.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. --Boundary-00=_9/q8McJiRf39g73--