refactor: rework the localization related part
This commit is contained in:
parent
0e3d5c519e
commit
c641be3377
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
*.user
|
*.user
|
||||||
*.user.*
|
*.user.*
|
||||||
|
translations/*.qm
|
||||||
|
30
Caesium.pro
30
Caesium.pro
@ -46,20 +46,22 @@ RESOURCES += \
|
|||||||
|
|
||||||
RC_FILE = caesium.rc
|
RC_FILE = caesium.rc
|
||||||
|
|
||||||
TRANSLATIONS = caesium_en.ts \
|
TRANSLATIONS = \
|
||||||
caesium_it.ts \
|
translations/caesium.ts \
|
||||||
caesium_ja.ts \
|
translations/caesium_en_US.ts \
|
||||||
caesium_fr.ts \
|
translations/caesium_it.ts \
|
||||||
caesium_br.ts \
|
translations/caesium_ja.ts \
|
||||||
caesium_de.ts \
|
translations/caesium_fr.ts \
|
||||||
caesium_tw.ts \
|
translations/caesium_br.ts \
|
||||||
caesium_sv.ts \
|
translations/caesium_de.ts \
|
||||||
caesium_cn.ts \
|
translations/caesium_zh_TW.ts \
|
||||||
caesium_pt-br.ts \
|
translations/caesium_sv.ts \
|
||||||
caesium_es.ts \
|
translations/caesium_zh_CN.ts \
|
||||||
caesium_kr.ts \
|
translations/caesium_pt_BR.ts \
|
||||||
caesium_gr.ts \
|
translations/caesium_es.ts \
|
||||||
caesium_ru.ts
|
translations/caesium_ko.ts \
|
||||||
|
translations/caesium_el_GR.ts \
|
||||||
|
translations/caesium_ru.ts
|
||||||
|
|
||||||
LIBS += -lQt5Concurrent
|
LIBS += -lQt5Concurrent
|
||||||
|
|
||||||
|
10
README.md
Normal file
10
README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
## Caesium (fork)
|
||||||
|
|
||||||
|
based on Caesium 1.7.0. You can get the original source code at [here](https://sourceforge.net/projects/caesium/files/1.7.0/). Changes made by this fork listed below.
|
||||||
|
|
||||||
|
### Resolved issues
|
||||||
|
|
||||||
|
- Remove country/region flags since the original filename have encoding issue which can cause a build failure, and also to avoid some potential regional internationalization issues. (216e1a9)
|
||||||
|
- Resolution display as -1x-1 for some images with unregular filename (e.g. `2IGYT%BD]SYY77Q7R041(WD.jpg` and `G9E@W$_Y4GYMWJY)%R24X~2.jpg`): Recompile under newer Qt version should works. Original Caesium official binary comes with Qt 5.1.0, Recompiled and tested under Qt 5.15.2.
|
||||||
|
- Click "Auto preview" checkbox and then click any image item will lead a crash. (0e3d5c5)
|
||||||
|
|
Binary file not shown.
Binary file not shown.
BIN
lang/25.汉语.qm
BIN
lang/25.汉语.qm
Binary file not shown.
BIN
lang/25.漢語.qm
BIN
lang/25.漢語.qm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lang/59.日本語.qm
BIN
lang/59.日本語.qm
Binary file not shown.
BIN
lang/66.한국어.qm
BIN
lang/66.한국어.qm
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +0,0 @@
|
|||||||
C:\Qt\Qt5.1.0\5.1.0\mingw48_32\bin\lupdate.exe C:\Users\Matteo\Documents\Progetti\Qt4\Caesium\Source\caesium.pro
|
|
||||||
pause
|
|
65
main.cpp
65
main.cpp
@ -1,6 +1,7 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
#
|
#
|
||||||
# Copyright (C) 2010-2013 Matteo Paonessa <matteo.paonessa@gmail.com>
|
# Copyright (C) 2010-2013 Matteo Paonessa <matteo.paonessa@gmail.com>
|
||||||
|
# 2021 Gary Wang <wzc782970009@gmail.com>
|
||||||
#
|
#
|
||||||
# This file is part of the Caesium distribution.
|
# This file is part of the Caesium distribution.
|
||||||
#
|
#
|
||||||
@ -19,6 +20,7 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
|
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
# Author: Matteo Paonessa <matteo.paonessa@gmail.com>
|
# Author: Matteo Paonessa <matteo.paonessa@gmail.com>
|
||||||
|
# Gary Wang <wzc782970009@gmail.com>
|
||||||
#
|
#
|
||||||
# ******************************************************************************/
|
# ******************************************************************************/
|
||||||
|
|
||||||
@ -30,37 +32,10 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
QString findLocaleN(int n, QString dir)
|
// QM_FILE_INSTALL_DIR should be defined from the CMakeLists file.
|
||||||
{
|
#ifndef QM_FILE_INSTALL_DIR
|
||||||
QDir langDir(dir + "/language");
|
#define QM_FILE_INSTALL_DIR ":/i18n/"
|
||||||
QStringList list = langDir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
|
#endif // QM_FILE_INSTALL_DIR
|
||||||
for (int i = list.length() - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
QString file = list.at(i);
|
|
||||||
QStringList name = file.split(".");
|
|
||||||
if (name[0] == QString::number(n))
|
|
||||||
{
|
|
||||||
return QString::number(n) + "." + name[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QString("31.English");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString findLocaleS(QString string, QString dir)
|
|
||||||
{
|
|
||||||
QDir langDir(dir + "/language");
|
|
||||||
QStringList list = langDir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
|
|
||||||
for (int i = list.length() - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
QString file = list.at(i);
|
|
||||||
QStringList name = file.split(".");
|
|
||||||
if (name[1] == string)
|
|
||||||
{
|
|
||||||
return name[0] + "." + string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QString("31.English");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -71,18 +46,24 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
a.addLibraryPath(a.applicationDirPath() + "/lib/");
|
a.addLibraryPath(a.applicationDirPath() + "/lib/");
|
||||||
|
|
||||||
int loc = QLocale::system().language();
|
QString locale = settings.value("Preferences/language").value<QString>();
|
||||||
QString locale = settings.value("Preferences/lang").value<QString>();
|
|
||||||
|
QString qmDir;
|
||||||
|
#ifdef _WIN32
|
||||||
|
qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations");
|
||||||
|
#else
|
||||||
|
qmDir = QT_STRINGIFY(QM_FILE_INSTALL_DIR);
|
||||||
|
#endif
|
||||||
|
|
||||||
QTranslator translator;
|
QTranslator translator;
|
||||||
if(locale.isEmpty())
|
if(locale.isEmpty()) {
|
||||||
{
|
if (translator.load(QString("caesium_%1").arg(QLocale::system().name()), qmDir)) {
|
||||||
translator.load(a.applicationDirPath() + "/language/" + findLocaleN(loc, a.applicationDirPath()));
|
a.installTranslator(&translator);
|
||||||
a.installTranslator(&translator);
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (translator.load(QString("caesium_%1").arg(locale), qmDir)) {
|
||||||
{
|
a.installTranslator(&translator);
|
||||||
translator.load(a.applicationDirPath() + "/language/" + findLocaleS(locale, a.applicationDirPath()));
|
}
|
||||||
a.installTranslator(&translator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap pixmap(":icons/splash.png");
|
QPixmap pixmap(":icons/splash.png");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
#
|
#
|
||||||
# Copyright (C) 2010-2013 Matteo Paonessa <matteo.paonessa@gmail.com>
|
# Copyright (C) 2010-2013 Matteo Paonessa <matteo.paonessa@gmail.com>
|
||||||
|
# 2021 Gary Wang <wzc782970009@gmail.com>
|
||||||
#
|
#
|
||||||
# This file is part of the Caesium distribution.
|
# This file is part of the Caesium distribution.
|
||||||
#
|
#
|
||||||
@ -19,6 +20,7 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
|
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
# Author: Matteo Paonessa <matteo.paonessa@gmail.com>
|
# Author: Matteo Paonessa <matteo.paonessa@gmail.com>
|
||||||
|
# Gary Wang <wzc782970009@gmail.com>
|
||||||
#
|
#
|
||||||
# ******************************************************************************/
|
# ******************************************************************************/
|
||||||
|
|
||||||
@ -62,16 +64,17 @@ Preferences::~Preferences()
|
|||||||
|
|
||||||
void Preferences::loadLanguages()
|
void Preferences::loadLanguages()
|
||||||
{
|
{
|
||||||
QDir langDir(QDir::currentPath() + "/language");
|
QDir langDir(QDir::currentPath() + "/translations");
|
||||||
QStringList list = langDir.entryList(QStringList("*.qm"), QDir::Files, QDir::NoSort);
|
QStringList list = langDir.entryList(QStringList("*.qm"), QDir::Files, QDir::NoSort);
|
||||||
for (int i = list.length() - 1; i >= 0; i--)
|
for (int i = list.length() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
QString file = list.at(i);
|
QString fileName = QFileInfo(list.at(i)).baseName();
|
||||||
QStringList infoList;
|
if (!fileName.startsWith("caesium")) continue;
|
||||||
QStringList name = file.split(".");
|
QString langCode = fileName.mid(8);
|
||||||
infoList << name[1];
|
QString langName = QLocale(langCode).nativeLanguageName();
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem(infoList, 0);
|
if (langName.isEmpty() || langCode.isEmpty()) continue;
|
||||||
item->setIcon(0, QIcon(":/icons/language/" + name[1] + ".png"));
|
|
||||||
|
QTreeWidgetItem *item = new QTreeWidgetItem({langName, langCode}, 0);
|
||||||
ui->languageTreeWidget->insertTopLevelItem(0, item);
|
ui->languageTreeWidget->insertTopLevelItem(0, item);
|
||||||
}
|
}
|
||||||
ui->languageTreeWidget->sortItems(0, Qt::AscendingOrder);
|
ui->languageTreeWidget->sortItems(0, Qt::AscendingOrder);
|
||||||
@ -171,7 +174,7 @@ void Preferences::on_applyButton_clicked()
|
|||||||
settings.setValue("Preferences/loadlastlist", ui->loadLastListCheckBox->isChecked());
|
settings.setValue("Preferences/loadlastlist", ui->loadLastListCheckBox->isChecked());
|
||||||
if (ui->languageTreeWidget->selectedItems().count() != 0)
|
if (ui->languageTreeWidget->selectedItems().count() != 0)
|
||||||
{
|
{
|
||||||
settings.setValue("Preferences/lang", ui->languageTreeWidget->selectedItems().at(0)->text(0));
|
settings.setValue("Preferences/language", ui->languageTreeWidget->selectedItems().at(0)->text(1));
|
||||||
QMessageBox::information(this,
|
QMessageBox::information(this,
|
||||||
tr("Information"),
|
tr("Information"),
|
||||||
tr("You need to restart the application before\nchanges take effect"),
|
tr("You need to restart the application before\nchanges take effect"),
|
||||||
|
1015
translations/caesium.ts
Normal file
1015
translations/caesium.ts
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user