Support translation domain in 'kde' translation system

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: 123872
wilder
Chusslove Illich (Часлав Илић) 11 years ago
parent 173b335927
commit 2fff683110
  1. 24
      autotests/kconfig_compiler/CMakeLists.txt
  2. 10
      autotests/kconfig_compiler/kconfigcompiler_test.cpp
  3. 53
      autotests/kconfig_compiler/klocalizedstring.h
  4. 16
      autotests/kconfig_compiler/test_translation.kcfg
  5. 25
      autotests/kconfig_compiler/test_translation_kde.cpp.ref
  6. 40
      autotests/kconfig_compiler/test_translation_kde.h.ref
  7. 6
      autotests/kconfig_compiler/test_translation_kde.kcfgc
  8. 25
      autotests/kconfig_compiler/test_translation_kde_domain.cpp.ref
  9. 40
      autotests/kconfig_compiler/test_translation_kde_domain.h.ref
  10. 7
      autotests/kconfig_compiler/test_translation_kde_domain.kcfgc
  11. 32
      autotests/kconfig_compiler/test_translation_kde_domain_main.cpp
  12. 32
      autotests/kconfig_compiler/test_translation_kde_main.cpp
  13. 23
      autotests/kconfig_compiler/test_translation_qt.cpp.ref
  14. 40
      autotests/kconfig_compiler/test_translation_qt.h.ref
  15. 6
      autotests/kconfig_compiler/test_translation_qt.kcfgc
  16. 32
      autotests/kconfig_compiler/test_translation_qt_main.cpp
  17. 8
      src/kconfig_compiler/kconfig_compiler.cpp

@ -233,3 +233,27 @@ gen_kcfg_test_source(test_qdebugcategory test_qcategory_SRCS)
ecm_add_test(TEST_NAME test_qdebugcategory ${test_qcategory_SRCS})
target_link_libraries(test_qdebugcategory KF5::ConfigGui)
########### next target ###############
set(test_translation_qt_SRCS test_translation_qt_main.cpp)
gen_kcfg_test_source(test_translation_qt test_translation_qt_SRCS KCFG test_translation.kcfg)
ecm_add_test(TEST_NAME test_translation_qt ${test_translation_qt_SRCS})
target_link_libraries(test_translation_qt KF5::ConfigGui)
########### next target ###############
set(test_translation_kde_SRCS test_translation_kde_main.cpp)
gen_kcfg_test_source(test_translation_kde test_translation_kde_SRCS KCFG test_translation.kcfg)
ecm_add_test(TEST_NAME test_translation_kde ${test_translation_kde_SRCS})
target_link_libraries(test_translation_kde KF5::ConfigGui)
########### next target ###############
set(test_translation_kde_domain_SRCS test_translation_kde_domain_main.cpp)
gen_kcfg_test_source(test_translation_kde_domain test_translation_kde_domain_SRCS KCFG test_translation.kcfg)
ecm_add_test(TEST_NAME test_translation_kde_domain ${test_translation_kde_domain_SRCS})
target_link_libraries(test_translation_kde_domain KF5::ConfigGui)

@ -45,8 +45,11 @@ static CompilerTestSet testCases = {
"test12.h", "test12.cpp",
"test13.h", "test13.cpp",
"test_dpointer.cpp", "test_dpointer.h",
"test_signal.cpp", "test_signal.h",
"test_qdebugcategory.cpp", "test_qdebugcategory.h",
"test_signal.cpp", "test_signal.h",
"test_translation_kde.cpp", "test_translation_kde.h",
"test_translation_kde_domain.cpp", "test_translation_kde_domain.h",
"test_translation_qt.cpp", "test_translation_qt.h",
Q_NULLPTR
};
@ -66,8 +69,11 @@ static CompilerTestSet testCasesToRun = {
"test12",
"test13",
"test_dpointer",
"test_signal",
"test_qdebugcategory",
"test_signal",
"test_translation_kde",
"test_translation_kde_domain",
"test_translation_qt",
Q_NULLPTR
};

@ -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;
}

@ -100,6 +100,7 @@ public:
generateProperties = codegenConfig.value("GenerateProperties", false).toBool();
if (trString == "kde") {
translationSystem = KdeTranslation;
translationDomain = codegenConfig.value("TranslationDomain").toString();
} else {
if (!trString.isEmpty() && trString != "qt") {
cerr << "Unknown translation system, falling back to Qt tr()" << endl;
@ -138,6 +139,7 @@ public:
bool useEnumTypes;
bool itemAccessors;
TranslationSystem translationSystem;
QString translationDomain;
bool generateProperties;
};
@ -1306,7 +1308,11 @@ QString translatedString(const CfgConfig &cfg, const QString &string, const QStr
break;
case CfgConfig::KdeTranslation:
if (!context.isEmpty()) {
if (!cfg.translationDomain.isEmpty() && !context.isEmpty()) {
result += "i18ndc(" + quoteString(cfg.translationDomain) + ", " + quoteString(context) + ", ";
} else if (!cfg.translationDomain.isEmpty()) {
result += "i18nd(" + quoteString(cfg.translationDomain) + ", ";
} else if (!context.isEmpty()) {
result += "i18nc(" + quoteString(context) + ", ";
} else {
result += "i18n(";

Loading…
Cancel
Save