• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mcallegari / qlcplus / 30175241190

25 Jul 2026 09:14PM UTC coverage: 35.287% (+0.005%) from 35.282%
30175241190

Pull #2083

github

web-flow
Merge ad27ec371 into 44b7820b7
Pull Request #2083: webaccess(-qml): improve localisation possibilities

6 of 10 new or added lines in 1 file covered. (60.0%)

18566 of 52614 relevant lines covered (35.29%)

41018.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.98
/engine/src/qlci18n.cpp
1
/*
2
  Q Light Controller
3
  qlci18n.cpp
4

5
  Copyright (C) Heikki Junnila
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#include <QCoreApplication>
21
#include <QTranslator>
22
#include <QLocale>
23
#include <QString>
24
#include <QDebug>
25
#include <QDir>
26
#include <QLibraryInfo>
27

28
#include "qlcconfig.h"
29
#include "qlcfile.h"
30
#include "qlci18n.h"
31

32
QString QLCi18n::s_defaultLocale = QString();
33
QString QLCi18n::s_translationFilePath = QString();
34
QString QLCi18n::s_loadedLanguage = QString();
35
QString QLCi18n::s_loadedLanguageHTML = QString();
36

37
void QLCi18n::init()
×
38
{
39
    // Set the default translation file path before parsing args
40
    QLCi18n::setTranslationFilePath(QLCFile::systemDirectory(TRANSLATIONDIR).absolutePath());
×
41
}
×
42

43
void QLCi18n::setDefaultLocale(const QString& locale)
3✔
44
{
45
    s_defaultLocale = locale;
3✔
46
}
3✔
47

48
QString QLCi18n::defaultLocale()
5✔
49
{
50
    return s_defaultLocale;
5✔
51
}
52

53
void QLCi18n::setTranslationFilePath(const QString& path)
2✔
54
{
55
    s_translationFilePath = path;
2✔
56
}
2✔
57

58
QString QLCi18n::translationFilePath()
5✔
59
{
60
    return s_translationFilePath;
5✔
61
}
62

63
void QLCi18n::setLoadedLanguage(const QString& language)
2✔
64
{
65
    s_loadedLanguage = language;
2✔
66
    s_loadedLanguageHTML = language.toLower().replace('_', '-');
2✔
67
}
2✔
68

NEW
69
QString QLCi18n::loadedLanguage()
×
70
{
NEW
71
    return s_loadedLanguage;
×
72
}
73

NEW
74
QString QLCi18n::loadedLanguageHTML()
×
75
{
NEW
76
    return s_loadedLanguageHTML;
×
77
}
78

79
bool QLCi18n::loadTranslation(const QString& component)
2✔
80
{
81
    const QString lc = defaultLocale().isEmpty() ? QLocale::system().name() : defaultLocale();
3✔
82
    const QString file(QString("%1_%2").arg(component).arg(lc));
2✔
83
    QTranslator* translator = new QTranslator(QCoreApplication::instance());
2✔
84
    if (translator->load(file, translationFilePath()) == true)
2✔
85
    {
86
        QCoreApplication::installTranslator(translator);
1✔
87
        setLoadedLanguage(lc);
1✔
88
        return true;
1✔
89
    }
90
    else
91
    {
92
        setLoadedLanguage("en");
1✔
93
        return false;
1✔
94
    }
95
}
2✔
96

97
bool QLCi18n::loadQtTranslation(const QString& component)
×
98
{
99
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
100
    const QString qtTranslationsPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
101
#else
102
    const QString qtTranslationsPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
×
103
#endif
104

105
    const QString lc = defaultLocale().isEmpty() ? QLocale::system().name() : defaultLocale();
×
106
    const QString file(QString("%1_%2").arg(component).arg(lc));
×
107
    QTranslator* qtTranslator = new QTranslator(QCoreApplication::instance());
×
108
    if (qtTranslator->load(file, qtTranslationsPath))
×
109
        return QCoreApplication::installTranslator(qtTranslator);
×
110
    else
111
        return false;
×
112
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc