Commit 51c5694d authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): supports translations

parent 21d99613
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>main_window</name>
<message>
<source>helloWorld</source>
<translation>Hello World!</translation>
</message>
</context>
</TS>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>main_window</name>
<message>
<source>helloWorld</source>
<translation>Bonjour le monde !</translation>
</message>
</context>
</TS>
......@@ -4,11 +4,22 @@ TARGET = linphone
TEMPLATE = app
SOURCES += \
src/app.cpp \
src/main.cpp \
src/views/main_window.cpp
HEADERS += \
src/views/main_window.h
src/app.hpp \
src/views/main_window.hpp
TRANSLATIONS = \
languages/en.ts \
languages/fr.ts
lupdate_only{
SOURCES = \
ui/*.qml
}
RESOURCES += \
resources.qrc
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/">
<!-- Languages. -->
<file>languages/en.qm</file>
<file>languages/fr.qm</file>
<!-- UI. -->
<file>ui/main_window.qml</file>
</qresource>
</RCC>
#include <cstdlib>
#include <QtDebug>
#include "app.hpp"
#define LANGUAGES_PATH ":/languages/"
App::App(int &argc, char **argv) : QGuiApplication(argc, argv) {
// Try to enable system translation by default. (else english)
if (m_translator.load(QString(LANGUAGES_PATH) + QLocale::system().name()) ||
m_translator.load(LANGUAGES_PATH "en")) {
this->installTranslator(&m_translator);
} else {
qWarning() << "No translation found.";
}
}
#ifndef APP_H_
#define APP_H_
#include <QGuiApplication>
#include <QTranslator>
class App : public QGuiApplication {
public:
App (int &argc, char **argv);
virtual ~App () {}
private:
QTranslator m_translator;
};
#endif // APP_H_
#include <cstdlib>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "app.hpp"
int main (int argc, char *argv[]) {
QGuiApplication app(argc, argv);
// Init main window.
App app(argc, argv);
QQmlApplicationEngine engine(QUrl("qrc:/ui/main_window.qml"));
// File not found.
if (engine.rootObjects().isEmpty())
exit(EXIT_FAILURE);
......
#include "main_window.h"
#include "main_window.hpp"
#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H
#endif // MAIN_WINDOW
import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
Window {
ApplicationWindow {
id: mainWindow
visible: true
width: 800
height: 600
header: ToolBar {
RowLayout {
anchors.fill: parent
}
}
footer: TabBar {
}
Text {
anchors.centerIn: parent
text: "Hello World!"
text: qsTr("helloWorld");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment