Skip to content

Commit 4bcbbac

Browse files
committed
feat(*): Added i18n localizations.
1 parent f1e7714 commit 4bcbbac

6 files changed

Lines changed: 205 additions & 140 deletions

File tree

hassio/BarWidget.qml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ NIconButton {
2424
return "Connected";
2525
}
2626

27+
readonly property string _statusLabel: {
28+
if (root._status === "Disconnected")
29+
return pluginApi?.tr("widget.status_disconnected") ?? "Disconnected";
30+
if (root._status === "Connecting")
31+
return pluginApi?.tr("widget.status_connecting") ?? "Connecting";
32+
return pluginApi?.tr("widget.status_connected") ?? "Connected";
33+
}
34+
2735
icon: "smart-home"
2836
colorFg: {
2937
switch (root._status) {
@@ -46,7 +54,9 @@ NIconButton {
4654

4755
onClicked: pluginApi.togglePanel(root.screen, this)
4856

49-
tooltipText: "Status: " + (root._status)
57+
tooltipText: pluginApi?.tr("widget.tooltip", {
58+
status: root._statusLabel
59+
}) ?? ("Status: " + root._statusLabel)
5060

5161
implicitHeight: Style.barHeight
5262

hassio/BrowserView.qml

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,56 @@ Item {
1616
clip: true
1717

1818
function load() {
19-
searchInput.text = ""
20-
root._searchText = ""
21-
_fetchAll()
19+
searchInput.text = "";
20+
root._searchText = "";
21+
_fetchAll();
2222
}
2323

2424
function _isPinned(entity_id) {
25-
const pinned = pluginApi?.pluginSettings?.entities ?? []
26-
return pinned.includes(entity_id)
25+
const pinned = pluginApi?.pluginSettings?.entities ?? [];
26+
return pinned.includes(entity_id);
2727
}
2828

2929
function _togglePin(entity_id) {
30-
let pinned = pluginApi?.pluginSettings?.entities ?? []
31-
pinned = [...pinned]
32-
const idx = pinned.indexOf(entity_id)
30+
let pinned = pluginApi?.pluginSettings?.entities ?? [];
31+
pinned = [...pinned];
32+
const idx = pinned.indexOf(entity_id);
3333
if (idx >= 0) {
34-
pinned.splice(idx, 1)
34+
pinned.splice(idx, 1);
3535
} else {
36-
pinned.push(entity_id)
36+
pinned.push(entity_id);
3737
}
38-
pluginApi.pluginSettings.entities = pinned
39-
pluginApi.saveSettings()
40-
root.main.refreshEntities()
41-
root._pinVersion++
38+
pluginApi.pluginSettings.entities = pinned;
39+
pluginApi.saveSettings();
40+
root.main.refreshEntities();
41+
root._pinVersion++;
4242
}
4343

44-
ListModel { id: _filteredModel }
44+
ListModel {
45+
id: _filteredModel
46+
}
4547

4648
function _refilter() {
47-
const q = root._searchText.toLowerCase()
48-
const source = root._allEntities
49+
const q = root._searchText.toLowerCase();
50+
const source = root._allEntities;
4951

50-
_filteredModel.clear()
52+
_filteredModel.clear();
5153

5254
for (const e of source) {
53-
if (!q ||
54-
e.entity_id.toLowerCase().includes(q) ||
55-
e.friendly_name.toLowerCase().includes(q)) {
56-
_filteredModel.append(e)
55+
if (!q || e.entity_id.toLowerCase().includes(q) || e.friendly_name.toLowerCase().includes(q)) {
56+
_filteredModel.append(e);
5757
}
5858
}
5959
}
6060

6161
// Call it when entities load
6262
function _fetchAll() {
63-
root._loading = true
64-
root.main.getAllStates(function(results) {
65-
root._allEntities = results
66-
root._refilter()
67-
root._loading = false
68-
})
63+
root._loading = true;
64+
root.main.getAllStates(function (results) {
65+
root._allEntities = results;
66+
root._refilter();
67+
root._loading = false;
68+
});
6969
}
7070

7171
ColumnLayout {
@@ -75,11 +75,11 @@ Item {
7575
NTextInput {
7676
id: searchInput
7777
Layout.fillWidth: true
78-
label: "Search"
79-
placeholderText: "Filter by name or entity ID..."
78+
label: pluginApi?.tr("browser.search_label") ?? "Search"
79+
placeholderText: pluginApi?.tr("browser.search_placeholder") ?? "Filter by name or entity ID..."
8080
onTextChanged: {
81-
root._searchText = text
82-
root._refilter()
81+
root._searchText = text;
82+
root._refilter();
8383
}
8484
}
8585

@@ -101,14 +101,15 @@ Item {
101101
RotationAnimation on rotation {
102102
running: root._loading
103103
loops: Animation.Infinite
104-
from: 0; to: 360
104+
from: 0
105+
to: 360
105106
duration: 1000
106107
}
107108
}
108109

109110
NText {
110111
Layout.alignment: Qt.AlignHCenter
111-
text: "Loading entities..."
112+
text: pluginApi?.tr("browser.loading") ?? "Loading entities..."
112113
color: Color.mOnSurfaceVariant
113114
pointSize: Style.fontSizeM
114115
}
@@ -137,12 +138,15 @@ Item {
137138
radius: Style.radiusM
138139

139140
readonly property bool pinned: {
140-
root._pinVersion
141-
return root._isPinned(model.entity_id)
141+
root._pinVersion;
142+
return root._isPinned(model.entity_id);
142143
}
143144

144145
RowLayout {
145-
anchors { fill: parent; margins: Style.marginM }
146+
anchors {
147+
fill: parent
148+
margins: Style.marginM
149+
}
146150
spacing: Style.marginM
147151

148152
ColumnLayout {
@@ -177,4 +181,4 @@ Item {
177181
}
178182
}
179183
}
180-
}
184+
}

0 commit comments

Comments
 (0)