fixed loading system locale from wrong place

This commit is contained in:
leca 2024-12-05 13:58:23 +03:00
parent c478dcf8d4
commit b7b7c054d3
8 changed files with 24 additions and 12 deletions

2
.gitignore vendored
View File

@ -35,6 +35,8 @@ Thumbs.db
/.qmake.cache
/.qmake.stash
*.qrc.depends
# qtcreator generated files
*.pro.user*
CMakeLists.txt.user*

View File

@ -55,7 +55,7 @@ else()
# Generate translation files for Qt 5
# QT5_ADD_TRANSLATION()
qt5_create_translation(QM_FILES "${TRANSLATION_SOURCES}" translations/en_US.ts translations/ru_RU.ts)
# qt_add_translation(checks-parser TS_FILES translations/en_US.ts translations/ru_RU.ts)
qt5_add_resources(TRANSLATIONQRC translations.qrc)
add_executable(checks-parser
${PROJECT_SOURCES}
goods/goods.h goods/goods.cpp
@ -75,12 +75,11 @@ else()
image_redactor/imageredactor.h image_redactor/imageredactor.cpp
solvecaptchadialog.h solvecaptchadialog.cpp solvecaptchadialog.ui
exceptions/ofdrequestexception.h exceptions/ofdrequestexception.cpp
${QM_FILES}
${TS_FILES}
# ${QM_FILES}
# ${TS_FILES}
translations.qrc
${TRANSLATIONQRC}
)
# configure_file(translations.qrc ${CMAKE_BINARY_DIR} COPYONLY)
# QT5_ADD_TRANSLATION(TRANSLATIONS ${CMAKE_SOURCE_DIR} translations/en_US.ts)
endif()

View File

@ -7,8 +7,6 @@ mkdir -p AppDir/usr/lib
mkdir -p AppDir/usr/share/tesseract-ocr/4.00/tessdata
cp -r /usr/share/tesseract-ocr/4.00/tessdata/* AppDir/usr/share/tesseract-ocr/4.00/tessdata
cp ../../checks-parser AppDir/usr/bin
cp ../../en_US.qm AppDir/
cp ../../ru_RU.qm AppDir/
echo \
"[Desktop Entry]

View File

@ -12,6 +12,8 @@
# include <filesystem>
using namespace std::filesystem;
#endif
#include <QFile>
#include <QTextStream>
#include <QTranslator>
int main(int argc, char *argv[]) {
@ -46,13 +48,17 @@ int main(int argc, char *argv[]) {
QString lang = "en_US";
if (s.get_all_settings().contains("language")) {
std::cout << "settings" << std::endl;
lang = QString::fromStdString(s.get_all_settings()["language"]);
} else if (translator.load(QLocale::system().name())) {
} else if (translator.load(":/translation/"+QLocale::system().name()+".qm")) {
std::cout << "system" << std::endl;
lang = QLocale::system().name();
} else {
std::cout << "default" << std::endl;
lang = QString::fromStdString("en_US");
}
translator.load(lang);
std::cout << lang.toStdString() << std::endl;
translator.load(":/translation/" + lang + ".qm");
a.installTranslator(&translator);
MainWindow w;

7
translations.qrc Normal file
View File

@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/translation">
<file>en_US.qm</file>
<file>ru_RU.qm</file>
</qresource>
<qresource prefix="/translations"/>
</RCC>

View File

@ -307,12 +307,12 @@
<context>
<name>SettingsDialog</name>
<message>
<location filename="../settingsdialog.cpp" line="135"/>
<location filename="../settingsdialog.cpp" line="134"/>
<source>You need to restart program to apply language changes</source>
<translation>Требуется перезагрузить программу, чтобы применить изменения языка</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="137"/>
<location filename="../settingsdialog.cpp" line="136"/>
<source>Restart required</source>
<translation>Требуется перезагрузка</translation>
</message>