Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KDESKTOP-1380-Linux-Bad-RN-link-when-default-language-set #458

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gui/parametersdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ void ParametersDialog::onDebugReporterDone(bool retCode, const QString &debugId)
EnableStateHolder _(this);

Language language = ParametersCache::instance()->parametersInfo().language();
QString languageCode = KDC::CommonUtility::languageCodeList(language).first();
QString languageCode = CommonUtility::languageCode(language);
QString swistranferUrl = QString(MANUALTRANSFER_URL).arg(languageCode.left(2));

CustomMessageBox msgBox(
Expand Down
2 changes: 1 addition & 1 deletion src/gui/versionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void VersionWidget::showReleaseNotes() const {

const Language &appLanguage = ParametersCache::instance()->parametersInfo().language();
QString languageCode = CommonUtility::languageCode(appLanguage);
if (languageCode.isEmpty()) languageCode = "en";
if (languageCode.isEmpty()) languageCode = CommonUtility::englishCode;
QDesktopServices::openUrl(
QUrl(QString("%1-%2-%3-%4.html")
.arg(APPLICATION_STORAGE_URL, versionInfo.fullVersion().c_str(), os, languageCode.left(2))));
Expand Down
39 changes: 15 additions & 24 deletions src/libcommon/utility/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ const int CommonUtility::logMaxSize = 500 * 1024 * 1024; // MB

SyncPath CommonUtility::_workingDirPath = "";

static const QString englishCode = "en";
static const QString frenchCode = "fr";
static const QString germanCode = "de";
static const QString spanishCode = "es";
static const QString italianCode = "it";
const QString CommonUtility::englishCode = "en";
const QString CommonUtility::frenchCode = "fr";
const QString CommonUtility::germanCode = "de";
const QString CommonUtility::spanishCode = "es";
const QString CommonUtility::italianCode = "it";

static std::random_device rd;
static std::default_random_engine gen(rd());
Expand Down Expand Up @@ -505,7 +505,7 @@ SyncPath CommonUtility::relativePath(const SyncPath &rootPath, const SyncPath &p
return relativePath;
}

QStringList CommonUtility::languageCodeList(const KDC::Language enforcedLocale) {
QStringList CommonUtility::languageCodeList(const Language enforcedLocale) {
QStringList uiLanguages = QLocale::system().uiLanguages();
uiLanguages.prepend(languageCode(enforcedLocale));

Expand All @@ -516,30 +516,21 @@ bool CommonUtility::languageCodeIsEnglish(const QString &languageCode) {
return languageCode.compare(englishCode) == 0;
}

QString CommonUtility::languageCode(const KDC::Language enforcedLocale) {
switch (enforcedLocale) {
case KDC::Language::Default: {
return QLocale::system().uiLanguages().isEmpty() ? QString() : QLocale::system().uiLanguages().first().left(2);
break;
}
case KDC::Language::English:
return englishCode;
break;
case KDC::Language::French:
QString CommonUtility::languageCode(const Language language) {
switch (language) {
case Language::French:
return frenchCode;
break;
case KDC::Language::German:
case Language::German:
return germanCode;
break;
case KDC::Language::Italian:
case Language::Italian:
return italianCode;
break;
case KDC::Language::Spanish:
case Language::Spanish:
return spanishCode;
case Language::English:
case Language::Default:
break;
}

return {};
return englishCode; // Return english by default.
}

SyncPath CommonUtility::getAppDir() {
Expand Down
11 changes: 8 additions & 3 deletions src/libcommon/utility/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ struct COMMON_EXPORT CommonUtility {
static bool compressFile(const QString &originalName, const QString &targetName,
const std::function<bool(int)> &progressCallback = nullptr);

static QString languageCode(::KDC::Language enforcedLocale);
static QStringList languageCodeList(::KDC::Language enforcedLocale);
static void setupTranslations(QCoreApplication *app, ::KDC::Language enforcedLocale);
static const QString englishCode;
static const QString frenchCode;
static const QString germanCode;
static const QString spanishCode;
static const QString italianCode;
static QString languageCode(Language language);
static QStringList languageCodeList(Language enforcedLocale);
static void setupTranslations(QCoreApplication *app, Language enforcedLocale);
static bool languageCodeIsEnglish(const QString &languageCode);

// Color threshold check
Expand Down
9 changes: 9 additions & 0 deletions test/libcommon/utility/testutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ void TestUtility::testGenerateRandomStringAlphaNum() {
CPPUNIT_ASSERT(err == 0);
}
}
void TestUtility::testLanguageCode() {
CPPUNIT_ASSERT_EQUAL(std::string("en"), CommonUtility::languageCode(Language::English).toStdString());
CPPUNIT_ASSERT_EQUAL(std::string("fr"), CommonUtility::languageCode(Language::French).toStdString());
CPPUNIT_ASSERT_EQUAL(std::string("de"), CommonUtility::languageCode(Language::German).toStdString());
CPPUNIT_ASSERT_EQUAL(std::string("es"), CommonUtility::languageCode(Language::Spanish).toStdString());
CPPUNIT_ASSERT_EQUAL(std::string("it"), CommonUtility::languageCode(Language::Italian).toStdString());
CPPUNIT_ASSERT_EQUAL(std::string("en"), CommonUtility::languageCode(Language::Default).toStdString());
CPPUNIT_ASSERT_EQUAL(std::string("en"), CommonUtility::languageCode(static_cast<Language>(18)).toStdString());
}

#ifdef _WIN32
void TestUtility::testGetLastErrorMessage() {
Expand Down
2 changes: 2 additions & 0 deletions test/libcommon/utility/testutility.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TestUtility : public CppUnit::TestFixture {
CPPUNIT_TEST(testCompressFile);
CPPUNIT_TEST(testCurrentVersion);
CPPUNIT_TEST(testGenerateRandomStringAlphaNum);
CPPUNIT_TEST(testLanguageCode);
#ifdef _WIN32
CPPUNIT_TEST(testGetLastErrorMessage);
#endif
Expand All @@ -45,6 +46,7 @@ class TestUtility : public CppUnit::TestFixture {
void testCompressFile();
void testCurrentVersion();
void testGenerateRandomStringAlphaNum();
void testLanguageCode();
#ifdef _WIN32
void testGetLastErrorMessage();
#endif
Expand Down
Loading