Skip to content

Commit bc8a221

Browse files
authored
Merge pull request #6 from machinekoder/translation
Translation
2 parents 5a28597 + 5a43751 commit bc8a221

13 files changed

Lines changed: 793 additions & 8 deletions

‎Machineface.pro‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
TEMPLATE = app
2+
NAME = Machineface
23

34
QT += qml quick widgets
45

56
SOURCES += main.cpp
67

78
RESOURCES += qml.qrc
89

10+
QML_FILES = $$PWD/$$NAME/*.qml
11+
OTHER_FILES += $$QML_FILES
12+
913
# Additional import path used to resolve QML modules in Qt Creator's code model
1014
QML_IMPORT_PATH =
1115

@@ -19,3 +23,7 @@ ios: {
1923
android: {
2024
LIBS += -lmachinetalk-protobuf
2125
}
26+
27+
TRANSLATIONS_PATH = $$PWD/translations
28+
TRANSLATIONS_OUT_PATH = $$PWD/$$NAME/translations
29+
include(translation.pri)

‎Machineface/AboutDialog.qml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import QtQuick.Window 2.0
77
Dialog {
88
property string version: "0.9"
99
id: aboutDialog
10-
title: "About Machineface"
10+
title: qsTr("About Machineface")
1111

1212
SystemPalette { id: systemPalette }
1313

‎Machineface/DisplayPanel.qml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ ColumnLayout {
1616

1717
TemperatureControl {
1818
componentName: "fdm-hbp"
19-
labelName: "Heated Bed"
19+
labelName: qsTr("Heated Bed")
2020
logHeight: parent.height * 0.25
2121
}
2222

2323
TemperatureControl {
2424
componentName: "fdm-hbc"
25-
labelName: "Heated Chamber"
25+
labelName: qsTr("Heated Chamber")
2626
logHeight: parent.height * 0.25
2727
}
2828

2929
Repeater {
3030
model: 10
3131
TemperatureControl {
3232
componentName: "fdm-e" + index
33-
labelName: "Extruder " + index
33+
labelName: qsTr("Extruder %1").arg(index)
3434
logHeight: parent.height * 0.25
3535
}
3636
}
@@ -39,15 +39,15 @@ ColumnLayout {
3939
model: 10
4040
FanControl {
4141
componentName: "fdm-f" + index
42-
labelName: "Fan " + index
42+
labelName: qsTr("Fan %1").arg(index)
4343
}
4444
}
4545

4646
Repeater {
4747
model: 3
4848
LightControl {
4949
componentName: "fdm-l" + index
50-
labelName: "Light " + index
50+
labelName: qsTr("Light %1").arg(index)
5151
}
5252
}
5353

‎Machineface/ToggleSettingCheck.qml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import QtQuick.Controls 1.2
44
CheckBox {
55
property string groupName: "group"
66
property string valueName: "value"
7-
text: qsTr("Group Value")
7+
text: "Group Value"
88
checked: applicationCore.settings.initialized && applicationCore.settings.values[groupName][valueName]
99
onClicked: {
1010
applicationCore.settings.setValue(groupName + "." + valueName, !applicationCore.settings.values[groupName][valueName])

‎Machineface/VelocityExtrusionControl.qml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Machinekit.Service 1.0
99

1010
ColumnLayout {
1111
id: root
12-
property string labelName: "Velocity Extrusion"
12+
property string labelName: qsTr("Velocity Extrusion")
1313
property bool wasConnected: false
1414

1515
visible: halRemoteComponent.ready || wasConnected
3.82 KB
Binary file not shown.
23 Bytes
Binary file not shown.
34 Bytes
Binary file not shown.

‎main.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <QApplication>
22
#include <QQmlApplicationEngine>
3+
#include <QTranslator>
4+
#include <QLibraryInfo>
35

46
int main(int argc, char *argv[])
57
{
@@ -10,6 +12,13 @@ int main(int argc, char *argv[])
1012
engine.addImportPath(QStringLiteral("assets:/imports"));
1113
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
1214

15+
QTranslator translator;
16+
if (translator.load(QLocale(), QLatin1String("machineface"),
17+
QLatin1String("_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
18+
{
19+
QCoreApplication::installTranslator(&translator);
20+
}
21+
1322
return app.exec();
1423
}
1524

‎translation.pri‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
TARGET_NAME = $$lower($$NAME)
2+
LANGUAGES = en ru de
3+
OUTPUT_DIR = $$TRANSLATIONS_OUT_PATH
4+
5+
defineReplace(prependAll) {
6+
for(a,$$1):result += $$2$${a}$$3
7+
return($$result)
8+
}
9+
10+
TRANSLATIONS = $$prependAll(LANGUAGES, $${TRANSLATIONS_PATH}/$${TARGET_NAME}_, .ts)
11+
TRANSLATIONS_OUT = $$prependAll(LANGUAGES, $${OUTPUT_DIR}/$${TARGET_NAME}_, .qm)
12+
13+
isEmpty(QMAKE_LUPDATE) {
14+
win32:QMAKE_LUPDATE = $$[QT_INSTALL_BINS]\lupdate.exe
15+
else:QMAKE_LUPDATE = $$[QT_INSTALL_BINS]/lupdate
16+
}
17+
18+
for(a,TRANSLATIONS): {
19+
system($$QMAKE_LUPDATE $$join(QML_FILES, " ") -locations none -no-ui-lines -ts $${a})
20+
}
21+
22+
isEmpty(QMAKE_LRELEASE) {
23+
win32:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\lrelease.exe
24+
else:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease
25+
}
26+
updateqm.input = TRANSLATIONS
27+
updateqm.output = $${OUTPUT_DIR}/${QMAKE_FILE_BASE}.qm
28+
updateqm.commands = $$QMAKE_MKDIR $$shell_path($$dirname(updateqm.output)) $$escape_expand(\n\t)
29+
updateqm.commands = $$QMAKE_LRELEASE $$shell_path(${QMAKE_FILE_IN}) -qm $$shell_path($${OUTPUT_DIR}/${QMAKE_FILE_BASE}.qm)
30+
updateqm.CONFIG += no_link
31+
updateqm.variable_out = PRE_TARGETDEPS
32+
QMAKE_EXTRA_COMPILERS += updateqm
33+
34+
updateqm_install.files = $$TRANSLATIONS_OUT
35+
updateqm_install.path = $$[QT_INSTALL_TRANSLATIONS]
36+
INSTALLS += updateqm_install
37+
38+
OTHER_FILES += $$TRANSLATIONS_OUT

0 commit comments

Comments
 (0)