aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBramastyo Harimukti <bramastyo.harimukti.santoso@pelagicore.com>2017-09-05 17:38:39 +0200
committerBramastyo Harimukti Santoso <bramastyo.harimukti.santoso@pelagicore.com>2017-09-13 14:16:39 +0000
commit4a93d527f66b786edde344c1ddeec20e377b6ac8 (patch)
tree8450749ebdfc16b87b3e4128a7ab16c01a67b2df
parentdb3b7a67bff0f5d7b7fff087c43d17e49e32db8b (diff)
Initial commit of Translation
- vehicle function pane is now updated and using translation - two languages (en and de) are added as initial internationalization Task-number: QTAUTO-189 Change-Id: I4710fdefe7c0d66d820f14d24fcbf0e8add060fd Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
-rw-r--r--apps/com.pelagicore.movies/MovieTracks.qml3
-rw-r--r--imports/assets/translations/de_DE.ts43
-rw-r--r--imports/assets/translations/en_GB.ts43
-rw-r--r--imports/shared/utils/Style.qml10
-rw-r--r--imports/system/models/settings/SettingsModel.qml22
-rw-r--r--plugins/plugins.pro3
-rw-r--r--plugins/translation/plugin.cpp50
-rw-r--r--plugins/translation/qmldir2
-rw-r--r--plugins/translation/translation.cpp82
-rw-r--r--plugins/translation/translation.h66
-rw-r--r--plugins/translation/translation.pro55
-rw-r--r--sysui/display/About.qml22
-rw-r--r--sysui/display/FunctionsPage.qml7
13 files changed, 395 insertions, 13 deletions
diff --git a/apps/com.pelagicore.movies/MovieTracks.qml b/apps/com.pelagicore.movies/MovieTracks.qml
index befa242..aff59a9 100644
--- a/apps/com.pelagicore.movies/MovieTracks.qml
+++ b/apps/com.pelagicore.movies/MovieTracks.qml
@@ -108,7 +108,8 @@ UIScreen {
}
Button {
text: 'PLAY NOW'
- Layout.alignment: Qt.AlignRight
+ Layout.preferredWidth: Style.hspan(4)
+ Layout.alignment: Qt.AlignLeft
onClicked: root.playMovie()
}
}
diff --git a/imports/assets/translations/de_DE.ts b/imports/assets/translations/de_DE.ts
new file mode 100644
index 0000000..0da61b0
--- /dev/null
+++ b/imports/assets/translations/de_DE.ts
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="de_DE">
+<context>
+ <name></name>
+ <message id="hill_descent_control_id">
+ <source>Hill Descent Control</source>
+ <translation>Bergabfahrhilfe</translation>
+ </message>
+ <message id="intelligent_speed_adaptation_id">
+ <source>Intelligent Speed Adaptation</source>
+ <translation>Intelligente Geschwindigkeitsanpassung</translation>
+ </message>
+ <message id="automatic_beam_switching_id">
+ <source>Automatic Beam Switching</source>
+ <translation>Automatische Fernlichtschaltung</translation>
+ </message>
+ <message id="collision_avoidance_id">
+ <source>Collision Avoidance</source>
+ <translation>Kollisionsvermeidung</translation>
+ </message>
+ <message id="lane_assist_id">
+ <source>Lane Assist</source>
+ <translation>Spur-Assistent</translation>
+ </message>
+ <message id="traffic_jam_assist_id">
+ <source>Traffic Jam Assist</source>
+ <translation>Stau-Assistent</translation>
+ </message>
+ <message id="driver_drowsiness_alert_id">
+ <source>Driver Drowsiness Alert</source>
+ <translation>Fahrermüdigkeitserkennung</translation>
+ </message>
+ <message id="park_assist_id">
+ <source>Park Assist</source>
+ <translation>Park Assistenzsysteme</translation>
+ </message>
+ <message id="language_id">
+ <source>Language</source>
+ <translation>Sprache</translation>
+ </message>
+</context>
+</TS>
diff --git a/imports/assets/translations/en_GB.ts b/imports/assets/translations/en_GB.ts
new file mode 100644
index 0000000..3a44fbd
--- /dev/null
+++ b/imports/assets/translations/en_GB.ts
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="en_GB">
+<context>
+ <name></name>
+ <message id="hill_descent_control_id">
+ <source>Hill Descent Control</source>
+ <translation>Hill Descent Control</translation>
+ </message>
+ <message id="intelligent_speed_adaptation_id">
+ <source>Intelligent Speed Adaptation</source>
+ <translation>Intelligent Speed Adaptation</translation>
+ </message>
+ <message id="automatic_beam_switching_id">
+ <source>Automatic Beam Switching</source>
+ <translation>Automatic Beam Switching</translation>
+ </message>
+ <message id="collision_avoidance_id">
+ <source>Automatic Beam Switching</source>
+ <translation>Automatic Beam Switching</translation>
+ </message>
+ <message id="lane_assist_id">
+ <source>Lane Assist</source>
+ <translation>Lane Assist</translation>
+ </message>
+ <message id="traffic_jam_assist_id">
+ <source>Traffic Jam Assist</source>
+ <translation>Traffic Jam Assist</translation>
+ </message>
+ <message id="driver_drowsiness_alert_id">
+ <source>Driver Drowsiness Alert</source>
+ <translation>Driver Drowsiness Alert</translation>
+ </message>
+ <message id="park_assist_id">
+ <source>Park Assist</source>
+ <translation>Park Assist</translation>
+ </message>
+ <message id="language_id">
+ <source>Language</source>
+ <translation>Language</translation>
+ </message>
+</context>
+</TS>
diff --git a/imports/shared/utils/Style.qml b/imports/shared/utils/Style.qml
index 1db9ecf..403ed18 100644
--- a/imports/shared/utils/Style.qml
+++ b/imports/shared/utils/Style.qml
@@ -33,6 +33,7 @@ pragma Singleton
import QtQuick 2.6
import com.pelagicore.styles.neptune 1.0
+import com.pelagicore.translation 1.0
QtObject {
id: root
@@ -107,6 +108,15 @@ QtObject {
property url gfxUrl: Qt.resolvedUrl(root.assetPath + 'gfx/')
property url fonts: Qt.resolvedUrl(root.assetPath + 'fonts/')
+ property alias languageLocale: translation.languageLocale
+ property QtObject translation: Translation {
+ id: translation
+ Component.onCompleted: {
+ setPath(root.assetPath + "translations/");
+ languageLocale = "en_GB";
+ }
+ }
+
function symbol(name, size, active) {
size = size || defaultSymbolSize;
return symbolUrl + (active ? '/active/' : '/') + name + '@' + size + '.png';
diff --git a/imports/system/models/settings/SettingsModel.qml b/imports/system/models/settings/SettingsModel.qml
index abf7617..a543287 100644
--- a/imports/system/models/settings/SettingsModel.qml
+++ b/imports/system/models/settings/SettingsModel.qml
@@ -39,6 +39,12 @@ QtObject {
property string unitSystem: "metric" // "metric" or "imp_us"
readonly property bool metric: unitSystem === "metric"
+ readonly property ListModel languages: ListModel {
+ ListElement { name: "en_GB" }
+ ListElement { name: "de_DE" }
+ }
+ property int currentLanguageIndex: 0
+
readonly property ListModel windowTransitions: ListModel {
ListElement { name: "Zoom" }
ListElement { name: "Tumble" }
@@ -88,42 +94,42 @@ QtObject {
property ListModel functions: ListModel {
ListElement {
- description: "Hill descent control"
+ description: "hill_descent_control_id"
icon: "hill_descent_control"
active: true
}
ListElement {
- description: "Intelligent speed adaptation"
+ description: "intelligent_speed_adaptation_id"
icon: "intelligent_speed_adaptation"
active: false
}
ListElement {
- description: "Automatic beam switching"
+ description: "automatic_beam_switching_id"
icon: "automatic_beam_switching"
active: true
}
ListElement {
- description: "Collision avoidance"
+ description: "collision_avoidance_id"
icon: "collision_avoidance"
active: false
}
ListElement {
- description: "Lane assist"
+ description: "lane_assist_id"
icon: "lane_keeping_assist"
active: false
}
ListElement {
- description: "Traffic jam assist"
+ description: "traffic_jam_assist_id"
icon: "traffic_jam_assist"
active: false
}
ListElement {
- description: "Driver drowsiness alert"
+ description: "driver_drowsiness_alert_id"
icon: "driver_drownsyness_alert"
active: true
}
ListElement {
- description: "Park assist"
+ description: "park_assist_id"
icon: "park_assist"
active: false
}
diff --git a/plugins/plugins.pro b/plugins/plugins.pro
index 06072b0..18aeb10 100644
--- a/plugins/plugins.pro
+++ b/plugins/plugins.pro
@@ -3,4 +3,5 @@ TEMPLATE = subdirs
SUBDIRS = datasource \
screenmanager \
comtqci18ndemo \
- styles
+ styles \
+ translation
diff --git a/plugins/translation/plugin.cpp b/plugins/translation/plugin.cpp
new file mode 100644
index 0000000..3952bc8
--- /dev/null
+++ b/plugins/translation/plugin.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Neptune IVI UI.
+**
+** $QT_BEGIN_LICENSE:GPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: GPL-3.0
+**
+****************************************************************************/
+
+#include <QtQml/qqmlextensionplugin.h>
+#include <qqml.h>
+#include "translation.h"
+
+class HoundPlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0")
+public:
+ virtual void registerTypes(const char *uri) override
+ {
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("com.pelagicore.translation"));
+ Q_UNUSED(uri);
+
+ qmlRegisterType<Translation>(uri, 1, 0, "Translation");
+ }
+};
+
+#include "plugin.moc"
diff --git a/plugins/translation/qmldir b/plugins/translation/qmldir
new file mode 100644
index 0000000..3410962
--- /dev/null
+++ b/plugins/translation/qmldir
@@ -0,0 +1,2 @@
+module com.pelagicore.translation
+plugin translationplugin
diff --git a/plugins/translation/translation.cpp b/plugins/translation/translation.cpp
new file mode 100644
index 0000000..2b79fd4
--- /dev/null
+++ b/plugins/translation/translation.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Neptune IVI UI.
+**
+** $QT_BEGIN_LICENSE:GPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: GPL-3.0
+**
+****************************************************************************/
+
+#include "translation.h"
+#include <QGuiApplication>
+#include <QtQml>
+#include <QScreen>
+#include <QDebug>
+
+Translation::Translation(QObject *parent)
+ : QObject(parent)
+{
+}
+
+void Translation::setPath(const QUrl &languageFilePath)
+{
+ m_languageFilePath = languageFilePath.toLocalFile();
+}
+
+void Translation::setLanguageLocale(const QString &languageLocale)
+{
+ if (m_languageLocale != languageLocale) {
+ if ( loadTranslationFile(languageLocale) ) {
+ m_languageLocale = languageLocale;
+
+ emit languageLocaleChanged();
+ emit languageChanged();
+ }
+ }
+}
+
+QString Translation::languageLocale() const
+{
+ return m_languageLocale;
+}
+
+bool Translation::loadTranslationFile(const QString &langLocale)
+{
+ QString fileToLoad(m_languageFilePath);
+ fileToLoad += langLocale + ".qm";
+
+ if ( m_translator.load(fileToLoad) ) {
+ qApp->installTranslator(&m_translator);
+
+ QEvent ev(QEvent::LanguageChange);
+ qApp->sendEvent(QQmlEngine::contextForObject(this)->engine(), &ev);
+
+ return true;
+ }
+
+ qWarning() << "Failed to load translation file";
+
+ return false;
+}
diff --git a/plugins/translation/translation.h b/plugins/translation/translation.h
new file mode 100644
index 0000000..c2e411b
--- /dev/null
+++ b/plugins/translation/translation.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Neptune IVI UI.
+**
+** $QT_BEGIN_LICENSE:GPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: GPL-3.0
+**
+****************************************************************************/
+
+#ifndef TRANSLATION_H
+#define TRANSLATION_H
+
+#include <QtCore/QObject>
+#include <QTranslator>
+#include <QUrl>
+
+class Translation : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QString languageLocale READ languageLocale WRITE setLanguageLocale NOTIFY languageLocaleChanged)
+
+public:
+ explicit Translation(QObject *parent = nullptr);
+
+ Q_INVOKABLE void setPath(const QUrl &languageFilePath);
+
+ void setLanguageLocale(const QString &languageLocale);
+ QString languageLocale() const;
+
+signals:
+ void languageLocaleChanged();
+ void languageChanged();
+
+protected:
+ bool loadTranslationFile(const QString &langLocale);
+
+ QString m_languageLocale;
+ QString m_languageFilePath;
+
+ QTranslator m_translator;
+};
+
+#endif // TRANSLATION_H
diff --git a/plugins/translation/translation.pro b/plugins/translation/translation.pro
new file mode 100644
index 0000000..b291aac
--- /dev/null
+++ b/plugins/translation/translation.pro
@@ -0,0 +1,55 @@
+TEMPLATE = lib
+TARGET = translationplugin
+QT += qml quick
+CONFIG += qt plugin c++11
+
+uri = com.pelagicore.translation
+load(qmlplugin)
+
+SOURCES += \
+ plugin.cpp \
+ translation.cpp \
+
+HEADERS += \
+ translation.h \
+
+# var, prepend, append
+defineReplace(prependAll) {
+ for(a,$$1):result += $$2$${a}$$3
+ return($$result)
+}
+
+assetsPath = $$PWD/../../imports/assets
+qmlSysUiPath = $$PWD/../../sysui
+# See qml files to scan while running lupdate/lrelease
+lupdate_only {
+ SOURCES += $$files($$shell_quote($$shell_path($${qmlSysUiPath}/))*.qml, true)
+}
+
+target.path = $$installPath
+
+supportedLocales = \
+ de_DE \
+ en_GB
+
+TRANSLATIONS = $$prependAll(supportedLocales, $$assetsPath/translations/, .ts)
+
+qtPrepareTool(LUPDATE, lupdate)
+qtPrepareTool(LRELEASE, lrelease)
+
+ts.commands = $$LUPDATE $$shell_quote($$_PRO_FILE_)
+QMAKE_EXTRA_TARGETS += ts
+
+qm.input = TRANSLATIONS
+qm.output = $$shadowed($$assetsPath/translations)/${QMAKE_FILE_BASE}.qm
+qm.variable_out = PRE_TARGETDEPS
+qm.commands = $${LRELEASE} -idbased ${QMAKE_FILE_IN} -qm ${QMAKE_FILE_OUT}
+qm.name = LRELEASE ${QMAKE_FILE_IN}
+qm.CONFIG += no_link
+QMAKE_EXTRA_COMPILERS += qm
+
+qmfiles.files = $$prependAll(supportedLocales, $$shadowed($$assetsPath/translations)/, .qm)
+qmfiles.path = $$INSTALL_PREFIX/neptune/imports/assets/translations
+qmfiles.CONFIG += no_check_exist
+
+INSTALLS += qmfiles
diff --git a/sysui/display/About.qml b/sysui/display/About.qml
index 81c7769..6afd4c8 100644
--- a/sysui/display/About.qml
+++ b/sysui/display/About.qml
@@ -161,6 +161,28 @@ Control {
}
}
+ RowLayout {
+ Layout.alignment: Qt.AlignCenter
+ Label { text: qsTrId("language_id") + ": " }
+ ComboBox {
+ id: languageComboBox
+ width: Style.hspan(5)
+ implicitWidth: width
+ model: SettingsModel.languages
+ textRole: "name"
+ onCurrentIndexChanged: {
+ SettingsModel.currentLanguageIndex = currentIndex;
+ }
+
+ Connections {
+ target: SettingsModel
+ onCurrentLanguageIndexChanged: {
+ Style.languageLocale = SettingsModel.languages.get(languageComboBox.currentIndex).name
+ }
+ }
+ }
+ }
+
}
Symbol {
diff --git a/sysui/display/FunctionsPage.qml b/sysui/display/FunctionsPage.qml
index 94aa511..38e7e57 100644
--- a/sysui/display/FunctionsPage.qml
+++ b/sysui/display/FunctionsPage.qml
@@ -73,6 +73,7 @@ UIPage {
width: GridView.view.cellWidth
height: GridView.view.cellHeight
spacing: 0
+
Rectangle {
id: highlightBar
width: 5
@@ -80,11 +81,11 @@ UIPage {
color: model.active ? NeptuneStyle.accentColor : NeptuneStyle.darkColor
}
Button {
- checked: model.active
- text: model.description
- checkable: true
width: parent.width - highlightBar.width
height: parent.height
+ text: qsTrId(model.description)
+ checked: model.active
+ checkable: true
onClicked: {
model.active = !model.active