diff --git a/CMakeLists.txt b/CMakeLists.txt index a75c564..06afe00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(SagoImageBrowser LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_AUTOMOC ON) -find_package(Qt6 REQUIRED COMPONENTS Widgets) +find_package(Qt6 REQUIRED COMPONENTS Widgets LinguistTools) find_package(PkgConfig REQUIRED) pkg_check_modules(EXIV2 REQUIRED exiv2) @@ -34,4 +34,8 @@ qt_add_executable(SagoImageBrowser src/thumbnaildelegate.h) target_include_directories(SagoImageBrowser PRIVATE ${EXIV2_INCLUDE_DIRS}) -target_link_libraries(SagoImageBrowser PRIVATE Qt6::Widgets ${EXIV2_LIBRARIES}) \ No newline at end of file +target_link_libraries(SagoImageBrowser PRIVATE Qt6::Widgets ${EXIV2_LIBRARIES}) + +qt_add_translations(SagoImageBrowser + TS_FILES translations/da.ts + RESOURCE_PREFIX "/translations") \ No newline at end of file diff --git a/extra/docker/Dockerfile b/extra/docker/Dockerfile index 96bbb18..d3579f3 100644 --- a/extra/docker/Dockerfile +++ b/extra/docker/Dockerfile @@ -9,6 +9,8 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ cmake \ pkg-config \ qt6-base-dev \ + qt6-tools-dev \ + qt6-l10n-tools \ libqt6core6 \ libqt6gui6 \ libqt6widgets6 \ diff --git a/src/imageviewwidget.cpp b/src/imageviewwidget.cpp index af5925d..0176ba6 100644 --- a/src/imageviewwidget.cpp +++ b/src/imageviewwidget.cpp @@ -296,22 +296,22 @@ void ImageViewWidget::paintEvent(QPaintEvent *) sc.description(ShortcutManager::ToggleHelp)}); entries.append({sc.displayKey(ShortcutManager::CloseViewer) + " / " + sc.displayKey(ShortcutManager::CloseViewerAlt), - QStringLiteral("Close viewer")}); + tr("Close viewer")}); entries.append({sc.displayKey(ShortcutManager::NextImage) + " / " + sc.displayKey(ShortcutManager::PrevImage), - QStringLiteral("Next / previous image")}); + tr("Next / previous image")}); entries.append({sc.displayKey(ShortcutManager::PanLeft) + " " + sc.displayKey(ShortcutManager::PanRight) + " " + sc.displayKey(ShortcutManager::PanUp) + " " + sc.displayKey(ShortcutManager::PanDown), - QStringLiteral("Pan image")}); + tr("Pan image")}); entries.append({sc.displayKey(ShortcutManager::ZoomOriginal), sc.description(ShortcutManager::ZoomOriginal)}); entries.append({sc.displayKey(ShortcutManager::ZoomFit), sc.description(ShortcutManager::ZoomFit)}); entries.append({sc.displayKey(ShortcutManager::ZoomIn) + " / " + sc.displayKey(ShortcutManager::ZoomOut), - QStringLiteral("Zoom in / out")}); + tr("Zoom in / out")}); entries.append({sc.displayKey(ShortcutManager::ToggleExif), sc.description(ShortcutManager::ToggleExif)}); entries.append({sc.displayKey(ShortcutManager::EditCaption), diff --git a/src/main.cpp b/src/main.cpp index 66a3644..ffa8a9e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,18 @@ #include +#include #include +#include #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); + QTranslator translator; + const QString locale = QLocale::system().name(); // e.g. "da_DK" + if (translator.load(":/translations/" + locale.left(2))) + app.installTranslator(&translator); + MainWindow w; w.showMaximized(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4b9d7d4..3ce7ccf 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -81,9 +81,9 @@ void MainWindow::setupUi() QListWidgetItem *item = new QListWidgetItem(label, m_rootList); item->setData(Qt::UserRole, path); }; - addRootItem("Home", QDir::homePath()); - addRootItem("Pictures", QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); - addRootItem("File System", QDir::rootPath()); + addRootItem(tr("Home"), QDir::homePath()); + addRootItem(tr("Pictures"), QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); + addRootItem(tr("File System"), QDir::rootPath()); m_rootList->setCurrentRow(0); m_treeView = new QTreeView; @@ -195,14 +195,14 @@ void MainWindow::setupMenuBar() "QMenuBar { padding: 1px 2px; }" "QMenuBar::item { padding: 2px 6px; }" ); - QMenu *viewMenu = m_menuBar->addMenu("&View"); + QMenu *viewMenu = m_menuBar->addMenu(tr("&View")); viewMenu->addAction(m_rootDock->toggleViewAction()); viewMenu->addAction(m_folderDock->toggleViewAction()); viewMenu->addAction(m_previewDock->toggleViewAction()); viewMenu->addAction(m_exifDock->toggleViewAction()); - QMenu *editMenu = m_menuBar->addMenu("&Edit"); - QAction *preferencesAction = editMenu->addAction("&Preferences"); + QMenu *editMenu = m_menuBar->addMenu(tr("&Edit")); + QAction *preferencesAction = editMenu->addAction(tr("&Preferences")); connect(preferencesAction, &QAction::triggered, this, &MainWindow::onPreferencesTriggered); } diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp index e87d3b6..0dade2e 100644 --- a/src/preferencesdialog.cpp +++ b/src/preferencesdialog.cpp @@ -17,7 +17,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent) { - setWindowTitle("Preferences"); + setWindowTitle(tr("Preferences")); setModal(true); setMinimumWidth(500); @@ -29,8 +29,8 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) mainLayout->addWidget(tabs); QHBoxLayout *buttonLayout = new QHBoxLayout; - QPushButton *okButton = new QPushButton("OK"); - QPushButton *cancelButton = new QPushButton("Cancel"); + QPushButton *okButton = new QPushButton(tr("OK")); + QPushButton *cancelButton = new QPushButton(tr("Cancel")); buttonLayout->addStretch(); buttonLayout->addWidget(okButton); @@ -51,15 +51,15 @@ void PreferencesDialog::setupGeneralTab(QTabWidget *tabs) QWidget *page = new QWidget; QVBoxLayout *pageLayout = new QVBoxLayout(page); - QGroupBox *imageGroup = new QGroupBox("Image Viewer", page); + QGroupBox *imageGroup = new QGroupBox(tr("Image Viewer"), page); QVBoxLayout *groupLayout = new QVBoxLayout(imageGroup); QHBoxLayout *bgColorLayout = new QHBoxLayout; - QLabel *bgColorLabel = new QLabel("Background Color:"); + QLabel *bgColorLabel = new QLabel(tr("Background Color:")); m_backgroundColorCombo = new QComboBox; - m_backgroundColorCombo->addItem("Black", "black"); - m_backgroundColorCombo->addItem("White", "white"); - m_backgroundColorCombo->addItem("Dark Gray", "darkgray"); + m_backgroundColorCombo->addItem(tr("Black"), "black"); + m_backgroundColorCombo->addItem(tr("White"), "white"); + m_backgroundColorCombo->addItem(tr("Dark Gray"), "darkgray"); bgColorLayout->addWidget(bgColorLabel); bgColorLayout->addWidget(m_backgroundColorCombo); @@ -68,7 +68,7 @@ void PreferencesDialog::setupGeneralTab(QTabWidget *tabs) groupLayout->addLayout(bgColorLayout); QHBoxLayout *cacheSizeLayout = new QHBoxLayout; - QLabel *cacheSizeLabel = new QLabel("Folder thumbnail cache (folders):"); + QLabel *cacheSizeLabel = new QLabel(tr("Folder thumbnail cache (folders):")); m_cacheSizeSpinBox = new QSpinBox; m_cacheSizeSpinBox->setRange(1, 20); m_cacheSizeSpinBox->setValue(4); @@ -78,10 +78,10 @@ void PreferencesDialog::setupGeneralTab(QTabWidget *tabs) groupLayout->addLayout(cacheSizeLayout); QHBoxLayout *thumbSizeLayout = new QHBoxLayout; - QLabel *thumbSizeLabel = new QLabel("Thumbnail cache size:"); + QLabel *thumbSizeLabel = new QLabel(tr("Thumbnail cache size:")); m_thumbnailSizeCombo = new QComboBox; - m_thumbnailSizeCombo->addItem("Normal (128 px)", "normal"); - m_thumbnailSizeCombo->addItem("Large (256 px)", "large"); + m_thumbnailSizeCombo->addItem(tr("Normal (128 px)"), "normal"); + m_thumbnailSizeCombo->addItem(tr("Large (256 px)"), "large"); thumbSizeLayout->addWidget(thumbSizeLabel); thumbSizeLayout->addWidget(m_thumbnailSizeCombo); thumbSizeLayout->addStretch(); @@ -89,18 +89,18 @@ void PreferencesDialog::setupGeneralTab(QTabWidget *tabs) pageLayout->addWidget(imageGroup); - QGroupBox *layoutGroup = new QGroupBox("Layout", page); + QGroupBox *layoutGroup = new QGroupBox(tr("Layout"), page); QVBoxLayout *layoutGroupLayout = new QVBoxLayout(layoutGroup); - m_lockDockingCheck = new QCheckBox("Lock docking (prevent accidental moves)"); + m_lockDockingCheck = new QCheckBox(tr("Lock docking (prevent accidental moves)")); layoutGroupLayout->addWidget(m_lockDockingCheck); - m_resetLayoutCheck = new QCheckBox("Reset layout to default when closing the menu"); + m_resetLayoutCheck = new QCheckBox(tr("Reset layout to default when closing the menu")); layoutGroupLayout->addWidget(m_resetLayoutCheck); pageLayout->addWidget(layoutGroup); pageLayout->addStretch(); - tabs->addTab(page, "General"); + tabs->addTab(page, tr("General")); } void PreferencesDialog::setupShortcutsTab(QTabWidget *tabs) @@ -119,7 +119,7 @@ void PreferencesDialog::setupShortcutsTab(QTabWidget *tabs) const int totalRows = configurableCount + 2; m_shortcutsTable = new QTableWidget(totalRows, 2, page); - m_shortcutsTable->setHorizontalHeaderLabels({"Action", "Key"}); + m_shortcutsTable->setHorizontalHeaderLabels({tr("Action"), tr("Key")}); m_shortcutsTable->horizontalHeader()->setStretchLastSection(true); m_shortcutsTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); m_shortcutsTable->verticalHeader()->hide(); @@ -151,7 +151,9 @@ void PreferencesDialog::setupShortcutsTab(QTabWidget *tabs) m_shortcutsTable->setItem(row, 0, descItem); auto *edit = new QKeySequenceEdit(mgr.shortcut(action)); +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) edit->setMaximumSequenceLength(1); +#endif connect(edit, &QKeySequenceEdit::keySequenceChanged, this, [this]() { highlightConflicts(); }); @@ -161,7 +163,7 @@ void PreferencesDialog::setupShortcutsTab(QTabWidget *tabs) }; // Image Viewer section - addSectionHeader("Image Viewer"); + addSectionHeader(tr("Image Viewer")); for (int i = 0; i < ShortcutManager::ActionCount; ++i) { auto action = static_cast(i); if (ShortcutManager::actionCategory(action) == ShortcutManager::CatImageViewer) @@ -169,7 +171,7 @@ void PreferencesDialog::setupShortcutsTab(QTabWidget *tabs) } // Browser section - addSectionHeader("Browser"); + addSectionHeader(tr("Browser")); for (int i = 0; i < ShortcutManager::ActionCount; ++i) { auto action = static_cast(i); if (ShortcutManager::actionCategory(action) == ShortcutManager::CatBrowser) @@ -179,7 +181,7 @@ void PreferencesDialog::setupShortcutsTab(QTabWidget *tabs) pageLayout->addWidget(m_shortcutsTable); QHBoxLayout *btnLayout = new QHBoxLayout; - QPushButton *resetBtn = new QPushButton("Reset to Defaults"); + QPushButton *resetBtn = new QPushButton(tr("Reset to Defaults")); btnLayout->addStretch(); btnLayout->addWidget(resetBtn); pageLayout->addLayout(btnLayout); @@ -198,7 +200,7 @@ void PreferencesDialog::setupShortcutsTab(QTabWidget *tabs) highlightConflicts(); }); - tabs->addTab(page, "Shortcuts"); + tabs->addTab(page, tr("Shortcuts")); } void PreferencesDialog::highlightConflicts() diff --git a/src/shortcutmanager.cpp b/src/shortcutmanager.cpp index 7f41d0b..a45111a 100644 --- a/src/shortcutmanager.cpp +++ b/src/shortcutmanager.cpp @@ -1,5 +1,6 @@ #include "shortcutmanager.h" +#include #include #include @@ -14,25 +15,25 @@ struct ActionInfo { // Order must match ShortcutManager::Action enum static const ActionInfo kDefaults[ShortcutManager::ActionCount] = { - {"ToggleHelp", "Show/hide keyboard shortcuts", QKeySequence(Qt::Key_F1), ShortcutManager::CatNotConfigurable}, - {"CloseViewer", "Close viewer", QKeySequence(Qt::Key_Escape), ShortcutManager::CatImageViewer}, - {"CloseViewerAlt", "Close viewer (alt)", QKeySequence(Qt::Key_Return), ShortcutManager::CatImageViewer}, - {"NextImage", "Next image", QKeySequence(Qt::Key_PageDown), ShortcutManager::CatImageViewer}, - {"PrevImage", "Previous image", QKeySequence(Qt::Key_PageUp), ShortcutManager::CatImageViewer}, - {"PanLeft", "Pan left", QKeySequence(Qt::Key_Left), ShortcutManager::CatImageViewer}, - {"PanRight", "Pan right", QKeySequence(Qt::Key_Right), ShortcutManager::CatImageViewer}, - {"PanUp", "Pan up", QKeySequence(Qt::Key_Up), ShortcutManager::CatImageViewer}, - {"PanDown", "Pan down", QKeySequence(Qt::Key_Down), ShortcutManager::CatImageViewer}, - {"ZoomOriginal", "Zoom to original size", QKeySequence(Qt::Key_Slash), ShortcutManager::CatImageViewer}, - {"ZoomFit", "Zoom to fit screen", QKeySequence(Qt::Key_Asterisk), ShortcutManager::CatImageViewer}, - {"ZoomIn", "Zoom in", QKeySequence(Qt::Key_Plus), ShortcutManager::CatImageViewer}, - {"ZoomOut", "Zoom out", QKeySequence(Qt::Key_Minus), ShortcutManager::CatImageViewer}, - {"ToggleExif", "Toggle EXIF info", QKeySequence(Qt::Key_I), ShortcutManager::CatImageViewer}, - {"EditCaption", "Edit caption", QKeySequence(Qt::Key_E), ShortcutManager::CatImageViewer}, - {"ToggleFullscreen","Toggle fullscreen", QKeySequence(Qt::Key_F11), ShortcutManager::CatImageViewer}, - {"ActivateEntry", "Open folder / image", QKeySequence(Qt::Key_Return), ShortcutManager::CatBrowser}, - {"PrevFolder", "Previous folder", QKeySequence(Qt::CTRL | Qt::Key_Left), ShortcutManager::CatBrowser}, - {"NextFolder", "Next folder", QKeySequence(Qt::CTRL | Qt::Key_Right), ShortcutManager::CatBrowser}, + {"ToggleHelp", QT_TR_NOOP("Show/hide keyboard shortcuts"), QKeySequence(Qt::Key_F1), ShortcutManager::CatNotConfigurable}, + {"CloseViewer", QT_TR_NOOP("Close viewer"), QKeySequence(Qt::Key_Escape), ShortcutManager::CatImageViewer}, + {"CloseViewerAlt", QT_TR_NOOP("Close viewer (alt)"), QKeySequence(Qt::Key_Return), ShortcutManager::CatImageViewer}, + {"NextImage", QT_TR_NOOP("Next image"), QKeySequence(Qt::Key_PageDown), ShortcutManager::CatImageViewer}, + {"PrevImage", QT_TR_NOOP("Previous image"), QKeySequence(Qt::Key_PageUp), ShortcutManager::CatImageViewer}, + {"PanLeft", QT_TR_NOOP("Pan left"), QKeySequence(Qt::Key_Left), ShortcutManager::CatImageViewer}, + {"PanRight", QT_TR_NOOP("Pan right"), QKeySequence(Qt::Key_Right), ShortcutManager::CatImageViewer}, + {"PanUp", QT_TR_NOOP("Pan up"), QKeySequence(Qt::Key_Up), ShortcutManager::CatImageViewer}, + {"PanDown", QT_TR_NOOP("Pan down"), QKeySequence(Qt::Key_Down), ShortcutManager::CatImageViewer}, + {"ZoomOriginal", QT_TR_NOOP("Zoom to original size"), QKeySequence(Qt::Key_Slash), ShortcutManager::CatImageViewer}, + {"ZoomFit", QT_TR_NOOP("Zoom to fit screen"), QKeySequence(Qt::Key_Asterisk), ShortcutManager::CatImageViewer}, + {"ZoomIn", QT_TR_NOOP("Zoom in"), QKeySequence(Qt::Key_Plus), ShortcutManager::CatImageViewer}, + {"ZoomOut", QT_TR_NOOP("Zoom out"), QKeySequence(Qt::Key_Minus), ShortcutManager::CatImageViewer}, + {"ToggleExif", QT_TR_NOOP("Toggle EXIF info"), QKeySequence(Qt::Key_I), ShortcutManager::CatImageViewer}, + {"EditCaption", QT_TR_NOOP("Edit caption"), QKeySequence(Qt::Key_E), ShortcutManager::CatImageViewer}, + {"ToggleFullscreen",QT_TR_NOOP("Toggle fullscreen"), QKeySequence(Qt::Key_F11), ShortcutManager::CatImageViewer}, + {"ActivateEntry", QT_TR_NOOP("Open folder / image"), QKeySequence(Qt::Key_Return), ShortcutManager::CatBrowser}, + {"PrevFolder", QT_TR_NOOP("Previous folder"), QKeySequence(Qt::CTRL | Qt::Key_Left), ShortcutManager::CatBrowser}, + {"NextFolder", QT_TR_NOOP("Next folder"), QKeySequence(Qt::CTRL | Qt::Key_Right), ShortcutManager::CatBrowser}, }; } // namespace @@ -129,7 +130,7 @@ QString ShortcutManager::actionDescription(Action action) { if (action < 0 || action >= ActionCount) return {}; - return QString::fromLatin1(kDefaults[action].description); + return QCoreApplication::translate("ShortcutManager", kDefaults[action].description); } ShortcutManager::Category ShortcutManager::actionCategory(Action action) diff --git a/translations/da.ts b/translations/da.ts new file mode 100644 index 0000000..e08d9a4 --- /dev/null +++ b/translations/da.ts @@ -0,0 +1,268 @@ + + + + + MainWindow + + Go + + + + Prev + Forrige + + + Next + Næste + + + Home + Hjem + + + Pictures + Billeder + + + File System + Filsystem + + + Roots + Rødder + + + Folders + Mapper + + + Preview + Forhåndsvisning + + + EXIF Info + EXIF-info + + + Field + Felt + + + Value + Værdi + + + &View + &Vis + + + &Edit + &Rediger + + + &Preferences + &Indstillinger + + + Cannot Edit Caption + Kan ikke redigere billedtekst + + + The file is write-protected. Cannot save caption. + Filen er skrivebeskyttet. Kan ikke gemme billedtekst. + + + Edit Caption + Rediger billedtekst + + + Caption-Abstract: + Billedtekst: + + + + PreferencesDialog + + Preferences + Indstillinger + + + OK + OK + + + Cancel + Annuller + + + Image Viewer + Billedfremviser + + + Background Color: + Baggrundsfarve: + + + Black + Sort + + + White + Hvid + + + Dark Gray + Mørkegrå + + + Folder thumbnail cache (folders): + Miniaturecache for mapper (antal): + + + Thumbnail cache size: + Miniaturestørrelse: + + + Normal (128 px) + Normal (128 px) + + + Large (256 px) + Stor (256 px) + + + Layout + Layout + + + Lock docking (prevent accidental moves) + Lås dokking (undgå utilsigtede flytninger) + + + Reset layout to default when closing the menu + Nulstil layout til standard ved lukning af menuen + + + General + Generelt + + + Shortcuts + Genveje + + + Action + Handling + + + Key + Tast + + + Browser + Browser + + + Reset to Defaults + Nulstil til standard + + + + ImageViewWidget + + Close viewer + Luk fremviser + + + Next / previous image + Næste / forrige billede + + + Pan image + Panorer billede + + + Zoom in / out + Zoom ind / ud + + + + ShortcutManager + + Show/hide keyboard shortcuts + Vis/skjul tastaturgenveje + + + Close viewer + Luk fremviser + + + Close viewer (alt) + Luk fremviser (alt) + + + Next image + Næste billede + + + Previous image + Forrige billede + + + Pan left + Panorer venstre + + + Pan right + Panorer højre + + + Pan up + Panorer op + + + Pan down + Panorer ned + + + Zoom to original size + Zoom til original størrelse + + + Zoom to fit screen + Zoom til skærmstørrelse + + + Zoom in + Zoom ind + + + Zoom out + Zoom ud + + + Toggle EXIF info + Vis/skjul EXIF-info + + + Edit caption + Rediger billedtekst + + + Toggle fullscreen + Skift fuldskærm + + + Open folder / image + Åbn mappe / billede + + + Previous folder + Forrige mappe + + + Next folder + Næste mappe + + +