Skip to content

Commit

Permalink
[feat] add translations
Browse files Browse the repository at this point in the history
  • Loading branch information
bgallois committed Nov 2, 2021
1 parent 5cc00e5 commit 661b3c5
Show file tree
Hide file tree
Showing 10 changed files with 1,017 additions and 34 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,29 @@ jobs:
run: |
sudo add-apt-repository ppa:beineri/opt-qt-5.15.2-bionic
sudo apt-get update
sudo apt-get install libgl1-mesa-dev qt515base qt515webengine qt515webchannel qt515multimedia qt515svg
sudo apt-get install libgl1-mesa-dev qt515base qt515webengine qt515webchannel qt515multimedia qt515svg qt515translations qt515tools
- name: build
run: |
export QTDIR=/opt/qt515
export PATH=/opt/qt515/bin:$PATH
qmake src/OpenJournal.pro CONFIG+=released
make
make clean
- name: appimage
run: |
cd build
export QTDIR=/opt/qt515
export PATH=/opt/qt515/bin:$PATH
wget -O deploy.AppImage https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/qt515/lib/
wget -O deploy.AppImage https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
chmod +x deploy.AppImage
cp ../io.github.bgallois.openjournal.desktop .
cp ../resources/openjournal.png .
./deploy.AppImage io.github.bgallois.openjournal.desktop -no-translations -bundle-non-qt-libs -appimage
mv OpenJournal*.AppImage OpenJournal-x86_64.AppImage
./deploy.AppImage -d io.github.bgallois.openjournal.desktop --appdir AppDir -i openjournal.png -e openjournal
mkdir AppDir/usr/share/openjournal/
cp *.qm AppDir/usr/share/openjournal
wget -O tool.AppImage https://github.com/AppImage/AppImageKit/releases/download/13/appimagetool-x86_64.AppImage
chmod +x tool.AppImage
./tool.AppImage AppDir/
- name: Linux artefact
uses: actions/upload-artifact@v1
with:
Expand Down Expand Up @@ -66,6 +70,7 @@ jobs:
nmake release
mkdir OpenJournal
cp build/OpenJournal.exe OpenJournal/OpenJournal.exe
cp build/*.qm OpenJournal/
windeployqt OpenJournal/OpenJournal.exe --release
copy C:\Windows\System32\vccorlib140.dll OpenJournal\
copy C:\Windows\System32\msvcp140.dll OpenJournal\
Expand Down Expand Up @@ -110,6 +115,7 @@ jobs:
make
cd build/
macdeployqt OpenJournal.app -always-overwrite -verbose=0
cp *.qm OpenJournal.app/Contents/Resources/
wget https://raw.githubusercontent.com/arl/macdeployqtfix/master/macdeployqtfix.py
#python2.7 macdeployqtfix.py OpenJournal.app/Contents/MacOS/OpenJournal ../../Qt/5.15.0/
hdiutil create -volname OpenJournal -srcfolder OpenJournal.app -ov -format UDZO OpenJournal.dmg
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ OpenJournal uses a database to store and retrieve user notes. This flexible appr
- [x] Secure journal
- [x] Lock
- [x] Keyword searching Ctrl + F
- [ ] Traduction
- [x] Traductions

## Screenshot

Expand Down
Binary file modified resources/openjournal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/readme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 30 additions & 16 deletions src/OpenJournal.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@ unix:macx {
TARGET = OpenJournal
}

unix:!macx {
TARGET = openjournal

# custom destination INSTALL_ROOT=$PWD/package_root make install
target.path = /usr/bin/
desktop.path = /usr/share/applications/
desktop.files = io.github.bgallois.openjournal.desktop
metainfo.path = /usr/share/metainfo/
metainfo.files = io.github.bgallois.openjournal.metainfo.xml
icon.path = /usr/share/icons/
icon.files = resources/openjournal.png
license.path = /usr/share/licenses/openjournal/
license.files = LICENSE
INSTALLS += target desktop metainfo icon license
}

DESTDIR=build
OBJECTS_DIR=build
MOC_DIR=build
Expand Down Expand Up @@ -73,5 +57,35 @@ FORMS += \
RESOURCES = \
../resources/openjournal.qrc

TRANSLATIONS = \
../translations/openjournal_en.ts \
../translations/openjournal_fr.ts
qtPrepareTool(LRELEASE, lrelease)
updateqm.input = TRANSLATIONS
updateqm.output = ${QMAKE_VAR_OBJECTS_DIR}/${QMAKE_FILE_BASE}.qm
updateqm.commands = $$LRELEASE -silent ${QMAKE_FILE_IN} -qm ${QMAKE_FILE_OUT}
updateqm.CONFIG += no_link target_predeps
QMAKE_EXTRA_COMPILERS += updateqm

ICON = ../resources/icon.icns
RC_ICONS = ../resources/icon.ico

unix:!macx {
TARGET = openjournal

# custom destination INSTALL_ROOT=$PWD/package_root make install
target.path = /usr/local/bin/
desktop.path = /usr/local/share/applications/
desktop.files = ../io.github.bgallois.openjournal.desktop
metainfo.path = /usr/local/share/metainfo/
metainfo.files = ../io.github.bgallois.openjournal.metainfo.xml
icon.path = /usr/local/share/icons/
icon.files = resources/openjournal.png
license.path = /usr/share/local/licenses/openjournal/
license.files = ../LICENSE
translation.path = /usr/local/share/openjournal/
translation.files = $$DESTDIR/*.qm
translation.CONFIG += no_check_exist
INSTALLS += target desktop metainfo icon license translation
}

62 changes: 50 additions & 12 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,34 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
isHelp = true; // Will display help message the first time app is closed

// Window geometry
settings = new QSettings();
settings = new QSettings(this);
this->resize(settings->value("mainwindow/size", QSize(400, 400)).toSize());
this->move(settings->value("mainwindow/pos", QPoint(200, 200)).toPoint());

// Translation
lang = settings->value("settings/language", "en").toString();
QString appDir = QCoreApplication::applicationDirPath();
QStringList translationLocation = {appDir, appDir + "/../Resources/", appDir + "/../share/openjournal/"}; // Windows, Macs bundle, Linux
for (auto const &a : translationLocation) {
QStringList availableLang = QDir(a).entryList({"*.qm"});
if (!availableLang.isEmpty()) {
translator.load("openjournal_" + lang, a);
qApp->installTranslator(&translator);
for (const auto &i : availableLang) { // Append one action by language
QAction *langAction = new QAction(i.mid(12, 2), this);
langAction->setCheckable(true);
if (lang == i.mid(12, 2)) {
langAction->setChecked(true);
}
connect(langAction, &QAction::triggered, [this, i]() {
lang = i.mid(12, 2);
reboot();
});
ui->menuLanguage->addAction(langAction);
}
}
}

// Tray integration
trayIcon = new QSystemTrayIcon(QIcon(":/openjournal.svg"), this);
QMenu *trayMenu = new QMenu;
Expand Down Expand Up @@ -115,7 +139,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
}

// Toolbar
QAction *actionAddAlarm = new QAction(QIcon(":/clocks.png"), "Add Alarm", this);
QAction *actionAddAlarm = new QAction(QIcon(":/clocks.png"), tr("Add Alarm"), this);
connect(actionAddAlarm, &QAction::triggered, [this]() {
ui->entry->moveCursor(QTextCursor::End);
AddAlarm *alarm = new AddAlarm();
Expand All @@ -126,34 +150,34 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
ui->toolBar->addAction(actionAddAlarm);
ui->toolBar->addSeparator();

QAction *actionToDoTemplate = new QAction(QIcon(":/todo.png"), "To do list template", this);
QAction *actionToDoTemplate = new QAction(QIcon(":/todo.png"), tr("To do list template"), this);
connect(actionToDoTemplate, &QAction::triggered, this, &MainWindow::insertToDoTemplate);
ui->toolBar->addAction(actionToDoTemplate);

QAction *actionListNumberedTemplate = new QAction(QIcon(":/listNumbered.png"), "Numbered list", this);
QAction *actionListNumberedTemplate = new QAction(QIcon(":/listNumbered.png"), tr("Numbered list"), this);
connect(actionListNumberedTemplate, &QAction::triggered, this, &MainWindow::insertListNumberedTemplate);
ui->toolBar->addAction(actionListNumberedTemplate);

QAction *actionListTemplate = new QAction(QIcon(":/list.png"), "Unordered list", this);
QAction *actionListTemplate = new QAction(QIcon(":/list.png"), tr("Unordered list"), this);
connect(actionListTemplate, &QAction::triggered, this, &MainWindow::insertListTemplate);
ui->toolBar->addAction(actionListTemplate);

QAction *actionTableTemplate = new QAction(QIcon(":/table.png"), "Table template", this);
QAction *actionTableTemplate = new QAction(QIcon(":/table.png"), tr("Table template"), this);
connect(actionTableTemplate, &QAction::triggered, this, &MainWindow::insertTableTemplate);
ui->toolBar->addAction(actionTableTemplate);

QAction *actionLinkTemplate = new QAction(QIcon(":/link.png"), "URL template", this);
QAction *actionLinkTemplate = new QAction(QIcon(":/link.png"), tr("URL template"), this);
connect(actionLinkTemplate, &QAction::triggered, this, &MainWindow::insertLinkTemplate);
ui->toolBar->addAction(actionLinkTemplate);
ui->toolBar->addSeparator();

QAction *actionLock = new QAction(QIcon(":/lock.png"), "Lock journal", this);
QAction *actionLock = new QAction(QIcon(":/lock.png"), tr("Lock journal"), this);
actionLock->setCheckable(true);
actionLock->setChecked(false);
connect(actionLock, &QAction::triggered, ui->entry, &QMarkdownTextEdit::setDisabled);
connect(actionLock, &QAction::triggered, [this](bool status) {
if (status) {
ui->statusBar->showMessage("The journal is locked");
ui->statusBar->showMessage(tr("The journal is locked"));
}
});
ui->toolBar->addAction(actionLock);
Expand Down Expand Up @@ -203,7 +227,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),

// Sonore
isSonore = settings->value("settings/sonore").toBool();
QAction *isSonoreAction = new QAction("Alarm Sound");
QAction *isSonoreAction = new QAction(tr("Alarm Sound"));
isSonoreAction->setCheckable(true);
isSonoreAction->setChecked(isSonore);
connect(isSonoreAction, &QAction::triggered, [this](bool state) {
Expand Down Expand Up @@ -336,24 +360,26 @@ void MainWindow::saveSettings() {
settings->setValue("mainwindow/pos", this->pos());
settings->setValue("settings/privacy", isPrivate);
settings->setValue("settings/sonore", isSonore);
settings->setValue("settings/language", lang);
}

void MainWindow::backup() {
QFile file(plannerName);
QFile copy(plannerName + ".back");
if (!copy.exists()) {
file.copy(plannerName + ".back");
ui->statusBar->showMessage("Journal was backed up " + plannerName + ".back");
ui->statusBar->showMessage(tr("Journal was backed up ") + plannerName + ".back");
}
else if (copy.exists()) {
copy.remove();
file.copy(plannerName + ".back");
ui->statusBar->showMessage("Cannot back up journal");
ui->statusBar->showMessage(tr("Cannot back up journal"));
}
}

MainWindow::~MainWindow() {
delete ui;
delete page;
}

void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) {
Expand Down Expand Up @@ -490,3 +516,15 @@ void MainWindow::insertListTemplate() {
ui->entry->insertPlainText("\n\n* Item 1\n* Item 2\n* Item 3\n\n");
}
}

void MainWindow::changeEvent(QEvent *event) {
if (event->type() == QEvent::LanguageChange) {
ui->retranslateUi(this);
}
}

void MainWindow::reboot() {
saveSettings();
qApp->quit();
QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
}
9 changes: 9 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QMainWindow>

#include <QAction>
#include <QActionGroup>
#include <QDebug>
#include <QDesktopServices>
#include <QGraphicsBlurEffect>
Expand All @@ -13,6 +14,7 @@
#include <QLCDNumber>
#include <QMap>
#include <QMessageBox>
#include <QProcess>
#include <QRegularExpression>
#include <QSettings>
#include <QSoundEffect>
Expand All @@ -24,6 +26,7 @@
#include <QStringLiteral>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QTranslator>
#include <QUrl>
#include <QWebChannel>
#include "addalarm.h"
Expand All @@ -43,6 +46,7 @@ class MainWindow : public QMainWindow {
~MainWindow();

private:
QString lang;
QSqlDatabase db;
JournalPage *page;
QString plannerName;
Expand All @@ -59,6 +63,10 @@ class MainWindow : public QMainWindow {
QLabel *statusMessage;
QLCDNumber *clock;
bool isHelp;
QTranslator translator;

protected:
void changeEvent(QEvent *event) override;

private slots:
void newJournal();
Expand All @@ -82,6 +90,7 @@ class MainWindow : public QMainWindow {
void insertLinkTemplate();
void insertListTemplate();
void insertListNumberedTemplate();
void reboot();

signals:
void exportLoadingFinished();
Expand Down
22 changes: 22 additions & 0 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ font: 11pt;</string>
<property name="title">
<string>Options</string>
</property>
<widget class="QMenu" name="menuLanguage">
<property name="title">
<string>Language</string>
</property>
</widget>
<addaction name="menuLanguage"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
Expand Down Expand Up @@ -330,6 +336,22 @@ color: #FFFFFF;</string>
<string>Show me the code</string>
</property>
</action>
<action name="actionEnglish">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>English</string>
</property>
</action>
<action name="actionFrench">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>French</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
Loading

0 comments on commit 661b3c5

Please sign in to comment.