diff options
17 files changed, 416 insertions, 3 deletions
diff --git a/autotests/kconfig_compiler/CMakeLists.txt b/autotests/kconfig_compiler/CMakeLists.txt index f73aec05..1ea6472a 100644 --- a/autotests/kconfig_compiler/CMakeLists.txt +++ b/autotests/kconfig_compiler/CMakeLists.txt @@ -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) + diff --git a/autotests/kconfig_compiler/kconfigcompiler_test.cpp b/autotests/kconfig_compiler/kconfigcompiler_test.cpp index 77a31a3e..231e3c45 100644 --- a/autotests/kconfig_compiler/kconfigcompiler_test.cpp +++ b/autotests/kconfig_compiler/kconfigcompiler_test.cpp @@ -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  }; diff --git a/autotests/kconfig_compiler/klocalizedstring.h b/autotests/kconfig_compiler/klocalizedstring.h new file mode 100644 index 00000000..1a878d9d --- /dev/null +++ b/autotests/kconfig_compiler/klocalizedstring.h @@ -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 diff --git a/autotests/kconfig_compiler/test_translation.kcfg b/autotests/kconfig_compiler/test_translation.kcfg new file mode 100644 index 00000000..ca2c2085 --- /dev/null +++ b/autotests/kconfig_compiler/test_translation.kcfg @@ -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> diff --git a/autotests/kconfig_compiler/test_translation_kde.cpp.ref b/autotests/kconfig_compiler/test_translation_kde.cpp.ref new file mode 100644 index 00000000..5c11133d --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_kde.cpp.ref @@ -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() +{ +} + diff --git a/autotests/kconfig_compiler/test_translation_kde.h.ref b/autotests/kconfig_compiler/test_translation_kde.h.ref new file mode 100644 index 00000000..f9b582c4 --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_kde.h.ref @@ -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 + diff --git a/autotests/kconfig_compiler/test_translation_kde.kcfgc b/autotests/kconfig_compiler/test_translation_kde.kcfgc new file mode 100644 index 00000000..402250c1 --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_kde.kcfgc @@ -0,0 +1,6 @@ +# Code generation options for kconfig_compiler_kf5 +File=test_translation.kcfg +NameSpace=TestNameSpace +ClassName=TestTranslationKde +SetUserTexts=true +TranslationSystem=kde diff --git a/autotests/kconfig_compiler/test_translation_kde_domain.cpp.ref b/autotests/kconfig_compiler/test_translation_kde_domain.cpp.ref new file mode 100644 index 00000000..66fc4cb9 --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_kde_domain.cpp.ref @@ -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() +{ +} + diff --git a/autotests/kconfig_compiler/test_translation_kde_domain.h.ref b/autotests/kconfig_compiler/test_translation_kde_domain.h.ref new file mode 100644 index 00000000..2fa42c71 --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_kde_domain.h.ref @@ -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 + diff --git a/autotests/kconfig_compiler/test_translation_kde_domain.kcfgc b/autotests/kconfig_compiler/test_translation_kde_domain.kcfgc new file mode 100644 index 00000000..5b242b41 --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_kde_domain.kcfgc @@ -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 diff --git a/autotests/kconfig_compiler/test_translation_kde_domain_main.cpp b/autotests/kconfig_compiler/test_translation_kde_domain_main.cpp new file mode 100644 index 00000000..64f8d59d --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_kde_domain_main.cpp @@ -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; +} diff --git a/autotests/kconfig_compiler/test_translation_kde_main.cpp b/autotests/kconfig_compiler/test_translation_kde_main.cpp new file mode 100644 index 00000000..a6a597c6 --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_kde_main.cpp @@ -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; +} diff --git a/autotests/kconfig_compiler/test_translation_qt.cpp.ref b/autotests/kconfig_compiler/test_translation_qt.cpp.ref new file mode 100644 index 00000000..f5ae7273 --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_qt.cpp.ref @@ -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() +{ +} + diff --git a/autotests/kconfig_compiler/test_translation_qt.h.ref b/autotests/kconfig_compiler/test_translation_qt.h.ref new file mode 100644 index 00000000..9831468b --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_qt.h.ref @@ -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 + diff --git a/autotests/kconfig_compiler/test_translation_qt.kcfgc b/autotests/kconfig_compiler/test_translation_qt.kcfgc new file mode 100644 index 00000000..fcdd26c6 --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_qt.kcfgc @@ -0,0 +1,6 @@ +# Code generation options for kconfig_compiler_kf5 +File=test_translation.kcfg +NameSpace=TestNameSpace +ClassName=TestTranslationQt +SetUserTexts=true +TranslationSystem=qt diff --git a/autotests/kconfig_compiler/test_translation_qt_main.cpp b/autotests/kconfig_compiler/test_translation_qt_main.cpp new file mode 100644 index 00000000..5e142fba --- /dev/null +++ b/autotests/kconfig_compiler/test_translation_qt_main.cpp @@ -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; +} diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp index 7160bb57..246cc92a 100644 --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -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(";  | 
