mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 14:44:01 +00:00
feat(app): supports translations
This commit is contained in:
parent
21d99613d4
commit
51c5694d4a
10 changed files with 93 additions and 10 deletions
11
tests/languages/en.ts
Normal file
11
tests/languages/en.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?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>
|
||||
11
tests/languages/fr.ts
Normal file
11
tests/languages/fr.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
<!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>
|
||||
|
|
|
|||
17
tests/src/app.cpp
Normal file
17
tests/src/app.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#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.";
|
||||
}
|
||||
}
|
||||
16
tests/src/app.hpp
Normal file
16
tests/src/app.hpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#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_
|
||||
|
|
@ -1,12 +1,15 @@
|
|||
#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);
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
#include "main_window.h"
|
||||
#include "main_window.hpp"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef MAIN_WINDOW_H
|
||||
#define MAIN_WINDOW_H
|
||||
|
||||
|
||||
#endif // MAIN_WINDOW
|
||||
|
|
@ -1,13 +1,23 @@
|
|||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue