i18n: zh_CN locale support

`CONFIG += embed_translations` is used.
This commit is contained in:
Gary Wang 2019-10-06 17:31:27 +08:00 committed by GitHub
parent 011e46b70b
commit b1260c0b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 212 additions and 9 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
# User files
*.user
# Translation files
*.qm

View File

@ -22,7 +22,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
CONFIG += c++11 lrelease embed_translations
SOURCES += \
main.cpp \
@ -43,7 +43,9 @@ HEADERS += \
opacityhelper.h \
toolbutton.h
FORMS +=
TRANSLATIONS = \
languages/PineapplePictures.ts \
languages/PineapplePictures_zh_CN.ts
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin

View File

@ -19,7 +19,7 @@ build_script:
- mingw32-make
- cd release
- del /a /f /q "*.o" "*.cpp" "*.h"
- windeployqt --no-quick-import --release .\PineapplePictures.exe
- windeployqt --no-quick-import --no-translations --no-opengl-sw --no-system-d3d-compiler --release .\PineapplePictures.exe
artifacts:
- path: build\release

View File

@ -12,7 +12,7 @@
GraphicsScene::GraphicsScene(QObject *parent)
: QGraphicsScene(parent)
{
showText("Drag image here");
showText(tr("Drag image here"));
}
GraphicsScene::~GraphicsScene()

View File

@ -29,7 +29,7 @@ void GraphicsView::showFromUrlList(const QList<QUrl> &urlList)
emit navigatorViewRequired(false, 0);
if (urlList.isEmpty()) {
// yeah, it's possible. dragging QQ's original sticker will trigger this, for example.
showText("File url list is empty");
showText(tr("File url list is empty"));
return;
}
QUrl url(urlList.first());
@ -43,7 +43,7 @@ void GraphicsView::showFromUrlList(const QList<QUrl> &urlList)
QImageReader imageReader(filePath);
QImage::Format imageFormat = imageReader.imageFormat();
if (imageFormat == QImage::Format_Invalid) {
showText("File is not a valid image");
showText(tr("File is not a valid image"));
} else {
showImage(QPixmap::fromImageReader(&imageReader));
}
@ -218,7 +218,7 @@ void GraphicsView::dragEnterEvent(QDragEnterEvent *event)
void GraphicsView::dragMoveEvent(QDragMoveEvent *event)
{
Q_UNUSED(event);
Q_UNUSED(event)
// by default, QGraphicsView/Scene will ignore the action if there are no QGraphicsItem under cursor.
// We actually doesn't care and would like to keep the drag event as-is, so just do nothing here.
}
@ -235,14 +235,14 @@ void GraphicsView::dropEvent(QDropEvent *event)
QImage img = qvariant_cast<QImage>(mimeData->imageData());
QPixmap pixmap = QPixmap::fromImage(img);
if (pixmap.isNull()) {
showText("Image data is invalid");
showText(tr("Image data is invalid"));
} else {
showImage(pixmap);
}
} else if (mimeData->hasText()) {
showText(mimeData->text());
} else {
showText("Not supported mimedata: " + mimeData->formats().first());
showText(tr("Not supported mimedata: %1").arg(mimeData->formats().first()));
}
}

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>GraphicsScene</name>
<message>
<location filename="../graphicsscene.cpp" line="15"/>
<source>Drag image here</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GraphicsView</name>
<message>
<location filename="../graphicsview.cpp" line="32"/>
<source>File url list is empty</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../graphicsview.cpp" line="46"/>
<source>File is not a valid image</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../graphicsview.cpp" line="238"/>
<source>Image data is invalid</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../graphicsview.cpp" line="245"/>
<source>Not supported mimedata: %1</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
<location filename="../mainwindow.cpp" line="229"/>
<location filename="../mainwindow.cpp" line="248"/>
<source>Stay on top</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="235"/>
<location filename="../mainwindow.cpp" line="249"/>
<source>Protected mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="241"/>
<source>Help</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="244"/>
<source>Launch application with image file path as argument to load the file.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="245"/>
<source>Drag and drop image file onto the window is also supported.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="247"/>
<source>Context menu option explanation:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="248"/>
<source>Make window stay on top of all other windows.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="249"/>
<source>Avoid close window accidentally. (eg. by double clicking the window)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>main</name>
<message>
<location filename="../main.cpp" line="18"/>
<source>File list.</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>GraphicsScene</name>
<message>
<location filename="../graphicsscene.cpp" line="15"/>
<source>Drag image here</source>
<translation></translation>
</message>
</context>
<context>
<name>GraphicsView</name>
<message>
<location filename="../graphicsview.cpp" line="32"/>
<source>File url list is empty</source>
<translation> URL </translation>
</message>
<message>
<location filename="../graphicsview.cpp" line="46"/>
<source>File is not a valid image</source>
<translation></translation>
</message>
<message>
<location filename="../graphicsview.cpp" line="238"/>
<source>Image data is invalid</source>
<translation></translation>
</message>
<message>
<location filename="../graphicsview.cpp" line="245"/>
<source>Not supported mimedata: %1</source>
<translation> MimeData %1</translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
<location filename="../mainwindow.cpp" line="229"/>
<location filename="../mainwindow.cpp" line="248"/>
<source>Stay on top</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="235"/>
<location filename="../mainwindow.cpp" line="249"/>
<source>Protected mode</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="241"/>
<source>Help</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="244"/>
<source>Launch application with image file path as argument to load the file.</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="245"/>
<source>Drag and drop image file onto the window is also supported.</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="247"/>
<source>Context menu option explanation:</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="248"/>
<source>Make window stay on top of all other windows.</source>
<translation>使</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="249"/>
<source>Avoid close window accidentally. (eg. by double clicking the window)</source>
<translation></translation>
</message>
</context>
<context>
<name>main</name>
<message>
<location filename="../main.cpp" line="18"/>
<source>File list.</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -1,15 +1,22 @@
#include "mainwindow.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QTranslator>
#include <QUrl>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// since we did `CONFIG += lrelease embed_translations`...
QTranslator translator;
translator.load(QString("PineapplePictures_%1").arg(QLocale::system().name()), ":/i18n/");
a.installTranslator(&translator);
// parse commandline arguments
QCommandLineParser parser;
parser.addPositionalArgument("File list", QCoreApplication::translate("main", "File list."));
parser.addHelpOption();
parser.process(a);

View File

@ -238,8 +238,22 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
});
protectedMode->setCheckable(true);
protectedMode->setChecked(m_protectedMode);
QAction * helpAction = new QAction(tr("Help"));
connect(helpAction, &QAction::triggered, this, [ = ](){
QStringList sl {
tr("Launch application with image file path as argument to load the file."),
tr("Drag and drop image file onto the window is also supported."),
"",
tr("Context menu option explanation:"),
(tr("Stay on top") + " : " + tr("Make window stay on top of all other windows.")),
(tr("Protected mode") + " : " + tr("Avoid close window accidentally. (eg. by double clicking the window)"))
};
m_graphicsView->showText(sl.join('\n'));
});
menu->addAction(stayOnTopMode);
menu->addAction(protectedMode);
menu->addSeparator();
menu->addAction(helpAction);
menu->exec(mapToGlobal(event->pos()));
menu->deleteLater();
@ -372,6 +386,7 @@ void MainWindow::toggleProtectedMode()
void MainWindow::toggleStayOnTop()
{
setWindowFlag(Qt::WindowStaysOnTopHint, !stayOnTop());
show();
}
bool MainWindow::stayOnTop()