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.cache
/.qmake.stash /.qmake.stash
*.qrc.depends
# qtcreator generated files # qtcreator generated files
*.pro.user* *.pro.user*
CMakeLists.txt.user* CMakeLists.txt.user*

View File

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

View File

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

View File

@ -12,6 +12,8 @@
# include <filesystem> # include <filesystem>
using namespace std::filesystem; using namespace std::filesystem;
#endif #endif
#include <QFile>
#include <QTextStream>
#include <QTranslator> #include <QTranslator>
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -46,13 +48,17 @@ int main(int argc, char *argv[]) {
QString lang = "en_US"; QString lang = "en_US";
if (s.get_all_settings().contains("language")) { if (s.get_all_settings().contains("language")) {
std::cout << "settings" << std::endl;
lang = QString::fromStdString(s.get_all_settings()["language"]); 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(); lang = QLocale::system().name();
} else { } else {
std::cout << "default" << std::endl;
lang = QString::fromStdString("en_US"); lang = QString::fromStdString("en_US");
} }
translator.load(lang); std::cout << lang.toStdString() << std::endl;
translator.load(":/translation/" + lang + ".qm");
a.installTranslator(&translator); a.installTranslator(&translator);
MainWindow w; 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> <context>
<name>SettingsDialog</name> <name>SettingsDialog</name>
<message> <message>
<location filename="../settingsdialog.cpp" line="135"/> <location filename="../settingsdialog.cpp" line="134"/>
<source>You need to restart program to apply language changes</source> <source>You need to restart program to apply language changes</source>
<translation>Требуется перезагрузить программу, чтобы применить изменения языка</translation> <translation>Требуется перезагрузить программу, чтобы применить изменения языка</translation>
</message> </message>
<message> <message>
<location filename="../settingsdialog.cpp" line="137"/> <location filename="../settingsdialog.cpp" line="136"/>
<source>Restart required</source> <source>Restart required</source>
<translation>Требуется перезагрузка</translation> <translation>Требуется перезагрузка</translation>
</message> </message>