From 2a6a22ed4b6ee9183372c0176b67b10bc2dbd1fd Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Wed, 27 Dec 2023 19:04:27 +0300 Subject: [PATCH] UI: TranslationManager: Minor refactor --- src/ui/manager/translationmanager.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ui/manager/translationmanager.cpp b/src/ui/manager/translationmanager.cpp index bd46f249..b2f58307 100644 --- a/src/ui/manager/translationmanager.cpp +++ b/src/ui/manager/translationmanager.cpp @@ -11,8 +11,12 @@ #include #include -#define TRANSLATION_FILE_PREFIX "i18n_" -#define TRANSLATION_FILE_SUFFIX ".qm" +namespace { + +constexpr const QLatin1String translationFilePrefix("i18n_"); +constexpr const QLatin1String translationFileSuffix(".qm"); + +} TranslationManager::TranslationManager(QObject *parent) : QObject(parent) { @@ -50,12 +54,11 @@ void TranslationManager::setupTranslation() void TranslationManager::setupLocales() { // Collect locales from i18n files - const auto i18nFileInfos = - QDir(i18nDir()).entryInfoList(QStringList() << ("*" TRANSLATION_FILE_SUFFIX)); + const auto i18nFileInfos = QDir(i18nDir()).entryInfoList({ ('*' + translationFileSuffix) }); const QString systemLanguageName = OsUtil::systemLanguageName(); - const int prefixLen = QLatin1String(TRANSLATION_FILE_PREFIX).size(); + const int prefixLen = translationFilePrefix.size(); m_locales.append(QLocale::system()); m_locales.append(QLocale(QLocale::English, QLocale::UnitedStates)); @@ -186,7 +189,7 @@ QTranslator *TranslationManager::loadTranslator(int language, const QLocale &loc // Load .qm file auto translator = new QTranslator(this); - if (!translator->load(TRANSLATION_FILE_PREFIX + locale.name(), i18nDir())) { + if (!translator->load(translationFilePrefix + locale.name(), i18nDir())) { delete translator; return nullptr; }