Skip to content

Commit

Permalink
Add translations for the SpaceBar
Browse files Browse the repository at this point in the history
Added SpaceBar translation with 'spaceIdentifier' property.

The translation can be added to the map inside
DeclarativeInputEngine.cpp, with 'space' as fallback.
  • Loading branch information
freaksdd authored and AndreaRicchi committed Sep 24, 2024
1 parent 194f51f commit 7b96d76
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/DeclarativeInputEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct DeclarativeInputEnginePrivate {
struct LayoutData {
QString layoutFile;
QString description;
QString spaceIdentifier = "Space";
};

DeclarativeInputEngine *_this;
Expand All @@ -32,7 +33,7 @@ struct DeclarativeInputEnginePrivate {
{DeclarativeInputEngine::Fr, {"FrLayout", "Français"}},
{DeclarativeInputEngine::It, {"ItLayout", "Italiano"}},
{DeclarativeInputEngine::Es, {"EsLayout", "Español"}},
{DeclarativeInputEngine::De, {"DeLayout", "Deutsch"}},
{DeclarativeInputEngine::De, {"DeLayout", "Deutsch", "Leerzeichen"}},
{DeclarativeInputEngine::Nl, {"NlLayout", "Nederlands"}},
{DeclarativeInputEngine::Pt, {"PtLayout", "Português"}},
{DeclarativeInputEngine::Cs, {"CsLayout", "Čeština"}},
Expand Down Expand Up @@ -165,3 +166,18 @@ QString DeclarativeInputEngine::descriptionOfLayout(QString layout) {
}
return d->layoutFiles.value(layoutVal, {}).description;
}

QString DeclarativeInputEngine::spaceIdentifierOfLayout(QString layout)
{
if (!inputLayoutValid(layout)) {
return "";
}
bool ok = false;
auto layoutVal = static_cast<InputLayouts>(
QMetaEnum::fromType<InputLayouts>().keyToValue(layout.toUtf8().data(),
&ok));
if (!ok) {
return "";
}
return d->layoutFiles.value(layoutVal, {}).spaceIdentifier;
}
8 changes: 6 additions & 2 deletions src/DeclarativeInputEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,15 @@ class DeclarativeInputEngine : public QObject {
Q_INVOKABLE QString fileOfLayout(QString layout);

/**
* Use this function to get the correct layout file for each language
* (only needed for languages that share one file)
* Use this function to get the correct description for each language
*/
Q_INVOKABLE QString descriptionOfLayout(QString layout);

/**
* Use this function to get the correct 'space'-identifier for each language
*/
Q_INVOKABLE QString spaceIdentifierOfLayout(QString layout);

public slots:
/**
* Emits a key click event for the given key, text and modifiers.
Expand Down
5 changes: 5 additions & 0 deletions src/qml/InputPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ Item {

function loadLettersLayout() {
var description = InputEngine.descriptionOfLayout(languageLayout);
var spaceIdentifier = InputEngine.spaceIdentifierOfLayout(languageLayout);
var source = InputEngine.fileOfLayout(languageLayout);
if (description !== "" && source !== "") {
layoutLoader.langDescription = description;
layoutLoader.spaceIdentifier = spaceIdentifier;
layoutLoader.setSource(source + ".qml", {
"inputPanel": root
});
} else {
layoutLoader.langDescription = "English";
layoutLoader.spaceIdentifier = "space";
layoutLoader.setSource("EnLayout.qml", {
"inputPanel": root
});
Expand Down Expand Up @@ -126,6 +129,8 @@ Item {

// lang description only needed for layouts that share a file
property string langDescription
// space identifier for the correct translation of the word "space"
property string spaceIdentifier

anchors {
fill: parent
Expand Down
1 change: 1 addition & 0 deletions src/qml/QwertyLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: spaceIdentifier
}

Key {
Expand Down
2 changes: 2 additions & 0 deletions src/qml/SymbolLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ Item {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: spaceIdentifier
}

Key {
Expand Down Expand Up @@ -492,6 +493,7 @@ Item {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: spaceIdentifier
}

Key {
Expand Down

0 comments on commit 7b96d76

Please sign in to comment.