From 4a93d527f66b786edde344c1ddeec20e377b6ac8 Mon Sep 17 00:00:00 2001 From: Bramastyo Harimukti Date: Tue, 5 Sep 2017 17:38:39 +0200 Subject: 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 --- apps/com.pelagicore.movies/MovieTracks.qml | 3 +- imports/assets/translations/de_DE.ts | 43 +++++++++++++ imports/assets/translations/en_GB.ts | 43 +++++++++++++ imports/shared/utils/Style.qml | 10 +++ imports/system/models/settings/SettingsModel.qml | 22 ++++--- plugins/plugins.pro | 3 +- plugins/translation/plugin.cpp | 50 +++++++++++++++ plugins/translation/qmldir | 2 + plugins/translation/translation.cpp | 82 ++++++++++++++++++++++++ plugins/translation/translation.h | 66 +++++++++++++++++++ plugins/translation/translation.pro | 55 ++++++++++++++++ sysui/display/About.qml | 22 +++++++ sysui/display/FunctionsPage.qml | 7 +- 13 files changed, 395 insertions(+), 13 deletions(-) create mode 100644 imports/assets/translations/de_DE.ts create mode 100644 imports/assets/translations/en_GB.ts create mode 100644 plugins/translation/plugin.cpp create mode 100644 plugins/translation/qmldir create mode 100644 plugins/translation/translation.cpp create mode 100644 plugins/translation/translation.h create mode 100644 plugins/translation/translation.pro 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 @@ + + + + + + + Hill Descent Control + Bergabfahrhilfe + + + Intelligent Speed Adaptation + Intelligente Geschwindigkeitsanpassung + + + Automatic Beam Switching + Automatische Fernlichtschaltung + + + Collision Avoidance + Kollisionsvermeidung + + + Lane Assist + Spur-Assistent + + + Traffic Jam Assist + Stau-Assistent + + + Driver Drowsiness Alert + Fahrermüdigkeitserkennung + + + Park Assist + Park Assistenzsysteme + + + Language + Sprache + + + 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 @@ + + + + + + + Hill Descent Control + Hill Descent Control + + + Intelligent Speed Adaptation + Intelligent Speed Adaptation + + + Automatic Beam Switching + Automatic Beam Switching + + + Automatic Beam Switching + Automatic Beam Switching + + + Lane Assist + Lane Assist + + + Traffic Jam Assist + Traffic Jam Assist + + + Driver Drowsiness Alert + Driver Drowsiness Alert + + + Park Assist + Park Assist + + + Language + Language + + + 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 +#include +#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(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 +#include +#include +#include + +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 +#include +#include + +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 -- cgit v1.2.3