i18n: zh_CN locale support
`CONFIG += embed_translations` is used.
This commit is contained in:
parent
011e46b70b
commit
b1260c0b41
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,5 @@
|
|||
# User files
|
||||
*.user
|
||||
|
||||
# Translation files
|
||||
*.qm
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
GraphicsScene::GraphicsScene(QObject *parent)
|
||||
: QGraphicsScene(parent)
|
||||
{
|
||||
showText("Drag image here");
|
||||
showText(tr("Drag image here"));
|
||||
}
|
||||
|
||||
GraphicsScene::~GraphicsScene()
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
88
languages/PineapplePictures.ts
Normal file
88
languages/PineapplePictures.ts
Normal 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>
|
88
languages/PineapplePictures_zh_CN.ts
Normal file
88
languages/PineapplePictures_zh_CN.ts
Normal 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>
|
7
main.cpp
7
main.cpp
|
@ -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);
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user