In applications translations can be looked up in the globally set translation domain, but in libraries it is necessary to link every i18n call to the library's own translation domain. A new code generation option TranslationDomain= is added to enable this. It has effect only if TranslationSystem=kde is set. Added unit tests to check generated translation calls. CHANGELOG: New code generation option TranslationDomain=, for use with TranslationSystem=kde; normally needed in libraries. REVIEW: 123872wilder
parent
173b335927
commit
2fff683110
17 changed files with 416 additions and 3 deletions
@ -0,0 +1,53 @@ |
||||
/*
|
||||
Copyright (c) 2015 Chusslove Illich <caslav.ilic@gmx.net> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in |
||||
all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/* This file is needed for test_translation_kde.
|
||||
* It provides fake i18n* in order to avoid dependency on Ki18n framework. |
||||
*/ |
||||
|
||||
#ifndef KLOCALIZEDSTRING_H |
||||
#define KLOCALIZEDSTRING_H |
||||
|
||||
inline QString i18n(const char *msgid) |
||||
{ |
||||
return QString::fromUtf8(msgid); |
||||
} |
||||
|
||||
inline QString i18nc(const char *msgctxt, const char *msgid) |
||||
{ |
||||
Q_UNUSED(msgctxt); |
||||
return QString::fromUtf8(msgid); |
||||
} |
||||
|
||||
inline QString i18nd(const char *domain, const char *msgid) |
||||
{ |
||||
Q_UNUSED(domain); |
||||
return QString::fromUtf8(msgid); |
||||
} |
||||
|
||||
inline QString i18ndc(const char *domain, const char *msgctxt, const char *msgid) |
||||
{ |
||||
Q_UNUSED(domain); |
||||
Q_UNUSED(msgctxt); |
||||
return QString::fromUtf8(msgid); |
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,16 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 |
||||
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > |
||||
<kcfgfile name="test_translation_rc"/> |
||||
|
||||
<group name="General"> |
||||
<entry type="Bool" key="Auto Save"> |
||||
<label>Enable automatic saving of calendar</label> |
||||
<whatsthis context="@info:whatsthis">Enable automatic saving of calendars to have calendars saved automatically.</whatsthis> |
||||
<default>false</default> |
||||
</entry> |
||||
</group> |
||||
|
||||
</kcfg> |
||||
@ -0,0 +1,25 @@ |
||||
// This file is generated by kconfig_compiler_kf5 from test_translation.kcfg. |
||||
// All changes you do to this file will be lost. |
||||
|
||||
#include "test_translation_kde.h" |
||||
|
||||
#include <klocalizedstring.h> |
||||
|
||||
using namespace TestNameSpace; |
||||
|
||||
TestTranslationKde::TestTranslationKde( ) |
||||
: KConfigSkeleton( QLatin1String( "test_translation_rc" ) ) |
||||
{ |
||||
setCurrentGroup( QLatin1String( "General" ) ); |
||||
|
||||
KConfigSkeleton::ItemBool *itemAutoSave; |
||||
itemAutoSave = new KConfigSkeleton::ItemBool( currentGroup(), QLatin1String( "Auto Save" ), mAutoSave, false ); |
||||
itemAutoSave->setLabel( i18n("Enable automatic saving of calendar") ); |
||||
itemAutoSave->setWhatsThis( i18nc("@info:whatsthis", "Enable automatic saving of calendars to have calendars saved automatically.") ); |
||||
addItem( itemAutoSave, QLatin1String( "AutoSave" ) ); |
||||
} |
||||
|
||||
TestTranslationKde::~TestTranslationKde() |
||||
{ |
||||
} |
||||
|
||||
@ -0,0 +1,40 @@ |
||||
// This file is generated by kconfig_compiler_kf5 from test_translation.kcfg. |
||||
// All changes you do to this file will be lost. |
||||
#ifndef TESTNAMESPACE_TESTTRANSLATIONKDE_H |
||||
#define TESTNAMESPACE_TESTTRANSLATIONKDE_H |
||||
|
||||
#include <qglobal.h> |
||||
#include <kconfigskeleton.h> |
||||
#include <QCoreApplication> |
||||
#include <QDebug> |
||||
|
||||
namespace TestNameSpace { |
||||
|
||||
class TestTranslationKde : public KConfigSkeleton |
||||
{ |
||||
public: |
||||
|
||||
TestTranslationKde( ); |
||||
~TestTranslationKde(); |
||||
|
||||
|
||||
/** |
||||
Get Enable automatic saving of calendar |
||||
*/ |
||||
bool autoSave() const |
||||
{ |
||||
return mAutoSave; |
||||
} |
||||
|
||||
protected: |
||||
|
||||
// General |
||||
bool mAutoSave; |
||||
|
||||
private: |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
|
||||
@ -0,0 +1,6 @@ |
||||
# Code generation options for kconfig_compiler_kf5 |
||||
File=test_translation.kcfg |
||||
NameSpace=TestNameSpace |
||||
ClassName=TestTranslationKde |
||||
SetUserTexts=true |
||||
TranslationSystem=kde |
||||
@ -0,0 +1,25 @@ |
||||
// This file is generated by kconfig_compiler_kf5 from test_translation.kcfg. |
||||
// All changes you do to this file will be lost. |
||||
|
||||
#include "test_translation_kde_domain.h" |
||||
|
||||
#include <klocalizedstring.h> |
||||
|
||||
using namespace TestNameSpace; |
||||
|
||||
TestTranslationKdeDomain::TestTranslationKdeDomain( ) |
||||
: KConfigSkeleton( QLatin1String( "test_translation_rc" ) ) |
||||
{ |
||||
setCurrentGroup( QLatin1String( "General" ) ); |
||||
|
||||
KConfigSkeleton::ItemBool *itemAutoSave; |
||||
itemAutoSave = new KConfigSkeleton::ItemBool( currentGroup(), QLatin1String( "Auto Save" ), mAutoSave, false ); |
||||
itemAutoSave->setLabel( i18nd("test-kcfg-kde", "Enable automatic saving of calendar") ); |
||||
itemAutoSave->setWhatsThis( i18ndc("test-kcfg-kde", "@info:whatsthis", "Enable automatic saving of calendars to have calendars saved automatically.") ); |
||||
addItem( itemAutoSave, QLatin1String( "AutoSave" ) ); |
||||
} |
||||
|
||||
TestTranslationKdeDomain::~TestTranslationKdeDomain() |
||||
{ |
||||
} |
||||
|
||||
@ -0,0 +1,40 @@ |
||||
// This file is generated by kconfig_compiler_kf5 from test_translation.kcfg. |
||||
// All changes you do to this file will be lost. |
||||
#ifndef TESTNAMESPACE_TESTTRANSLATIONKDEDOMAIN_H |
||||
#define TESTNAMESPACE_TESTTRANSLATIONKDEDOMAIN_H |
||||
|
||||
#include <qglobal.h> |
||||
#include <kconfigskeleton.h> |
||||
#include <QCoreApplication> |
||||
#include <QDebug> |
||||
|
||||
namespace TestNameSpace { |
||||
|
||||
class TestTranslationKdeDomain : public KConfigSkeleton |
||||
{ |
||||
public: |
||||
|
||||
TestTranslationKdeDomain( ); |
||||
~TestTranslationKdeDomain(); |
||||
|
||||
|
||||
/** |
||||
Get Enable automatic saving of calendar |
||||
*/ |
||||
bool autoSave() const |
||||
{ |
||||
return mAutoSave; |
||||
} |
||||
|
||||
protected: |
||||
|
||||
// General |
||||
bool mAutoSave; |
||||
|
||||
private: |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
|
||||
@ -0,0 +1,7 @@ |
||||
# Code generation options for kconfig_compiler_kf5 |
||||
File=test_translation.kcfg |
||||
NameSpace=TestNameSpace |
||||
ClassName=TestTranslationKdeDomain |
||||
SetUserTexts=true |
||||
TranslationSystem=kde |
||||
TranslationDomain=test-kcfg-kde |
||||
@ -0,0 +1,32 @@ |
||||
/*
|
||||
Copyright (c) 2015 Chusslove Illich <caslav.ilic@gmx.net> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in |
||||
all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "test_translation_kde_domain.h" |
||||
#include <QGuiApplication> |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
QGuiApplication app(argc, argv); |
||||
Q_UNUSED(app); |
||||
TestNameSpace::TestTranslationKdeDomain *t = new TestNameSpace::TestTranslationKdeDomain(); |
||||
delete t; |
||||
return 0; |
||||
} |
||||
@ -0,0 +1,32 @@ |
||||
/*
|
||||
Copyright (c) 2015 Chusslove Illich <caslav.ilic@gmx.net> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in |
||||
all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "test_translation_kde.h" |
||||
#include <QGuiApplication> |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
QGuiApplication app(argc, argv); |
||||
Q_UNUSED(app); |
||||
TestNameSpace::TestTranslationKde *t = new TestNameSpace::TestTranslationKde(); |
||||
delete t; |
||||
return 0; |
||||
} |
||||
@ -0,0 +1,23 @@ |
||||
// This file is generated by kconfig_compiler_kf5 from test_translation.kcfg. |
||||
// All changes you do to this file will be lost. |
||||
|
||||
#include "test_translation_qt.h" |
||||
|
||||
using namespace TestNameSpace; |
||||
|
||||
TestTranslationQt::TestTranslationQt( ) |
||||
: KConfigSkeleton( QLatin1String( "test_translation_rc" ) ) |
||||
{ |
||||
setCurrentGroup( QLatin1String( "General" ) ); |
||||
|
||||
KConfigSkeleton::ItemBool *itemAutoSave; |
||||
itemAutoSave = new KConfigSkeleton::ItemBool( currentGroup(), QLatin1String( "Auto Save" ), mAutoSave, false ); |
||||
itemAutoSave->setLabel( QCoreApplication::translate("TestTranslationQt", "Enable automatic saving of calendar") ); |
||||
itemAutoSave->setWhatsThis( /*: @info:whatsthis */ QCoreApplication::translate("TestTranslationQt", "Enable automatic saving of calendars to have calendars saved automatically.") ); |
||||
addItem( itemAutoSave, QLatin1String( "AutoSave" ) ); |
||||
} |
||||
|
||||
TestTranslationQt::~TestTranslationQt() |
||||
{ |
||||
} |
||||
|
||||
@ -0,0 +1,40 @@ |
||||
// This file is generated by kconfig_compiler_kf5 from test_translation.kcfg. |
||||
// All changes you do to this file will be lost. |
||||
#ifndef TESTNAMESPACE_TESTTRANSLATIONQT_H |
||||
#define TESTNAMESPACE_TESTTRANSLATIONQT_H |
||||
|
||||
#include <qglobal.h> |
||||
#include <kconfigskeleton.h> |
||||
#include <QCoreApplication> |
||||
#include <QDebug> |
||||
|
||||
namespace TestNameSpace { |
||||
|
||||
class TestTranslationQt : public KConfigSkeleton |
||||
{ |
||||
public: |
||||
|
||||
TestTranslationQt( ); |
||||
~TestTranslationQt(); |
||||
|
||||
|
||||
/** |
||||
Get Enable automatic saving of calendar |
||||
*/ |
||||
bool autoSave() const |
||||
{ |
||||
return mAutoSave; |
||||
} |
||||
|
||||
protected: |
||||
|
||||
// General |
||||
bool mAutoSave; |
||||
|
||||
private: |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
|
||||
@ -0,0 +1,6 @@ |
||||
# Code generation options for kconfig_compiler_kf5 |
||||
File=test_translation.kcfg |
||||
NameSpace=TestNameSpace |
||||
ClassName=TestTranslationQt |
||||
SetUserTexts=true |
||||
TranslationSystem=qt |
||||
@ -0,0 +1,32 @@ |
||||
/*
|
||||
Copyright (c) 2015 Chusslove Illich <caslav.ilic@gmx.net> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in |
||||
all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "test_translation_qt.h" |
||||
#include <QGuiApplication> |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
QGuiApplication app(argc, argv); |
||||
Q_UNUSED(app); |
||||
TestNameSpace::TestTranslationQt *t = new TestNameSpace::TestTranslationQt(); |
||||
delete t; |
||||
return 0; |
||||
} |
||||
Loading…
Reference in new issue