diff --git a/js/common/util/compute_state_display.js b/js/common/util/compute_state_display.js
index 5894146d88..f62e1a0318 100644
--- a/js/common/util/compute_state_display.js
+++ b/js/common/util/compute_state_display.js
@@ -53,9 +53,11 @@ export default function computeStateDisplay(localize, stateObj, language) {
} else {
stateObj._stateDisplay = localize(`state.${domain}.${stateObj.state}`);
}
- // Fall back to default or raw state if nothing else matches.
+ // Fall back to default, component backend translation, or raw state if nothing else matches.
stateObj._stateDisplay = stateObj._stateDisplay
- || localize(`state.default.${stateObj.state}`) || stateObj.state;
+ || localize(`state.default.${stateObj.state}`)
+ || localize(`component.${domain}.state.${stateObj.state}`)
+ || stateObj.state;
}
return stateObj._stateDisplay;
diff --git a/src/components/entity/ha-state-label-badge.html b/src/components/entity/ha-state-label-badge.html
index 10ddb845f0..75fff7b45d 100644
--- a/src/components/entity/ha-state-label-badge.html
+++ b/src/components/entity/ha-state-label-badge.html
@@ -1,6 +1,7 @@
+
@@ -37,7 +38,7 @@
{
+ // If we've switched selected languages just ignore this response
+ if (!this.hass.selectedLanguage === language) return;
+
+ this._updateResources(language, result.resources);
+ });
+ }
+
_updateResources(language, data) {
// Update the language in hass, and update the resources with the newly
// loaded resources. This merges the new data on top of the old data for
@@ -201,6 +213,7 @@ class HomeAssistant extends Polymer.Element {
var reconnected = () => {
this._updateHass({ connected: true });
+ this.loadBackendTranslations();
};
conn.addEventListener('ready', reconnected);
@@ -240,6 +253,8 @@ class HomeAssistant extends Polymer.Element {
unsubThemes = unsub;
});
+ this.loadBackendTranslations();
+
this.unsubConnection = function () {
conn.removeEventListener('ready', reconnected);
conn.removeEventListener('disconnected', disconnected);
@@ -307,6 +322,7 @@ class HomeAssistant extends Polymer.Element {
this._updateHass({ selectedLanguage: event.detail.language });
this.$.storage.storeState();
this.loadResources();
+ this.loadBackendTranslations();
this.loadTranslationFragment(this.panelUrl);
}
diff --git a/test-mocha/common/util/compute_state_display.js b/test-mocha/common/util/compute_state_display.js
index 542f11effe..ce925dc43e 100644
--- a/test-mocha/common/util/compute_state_display.js
+++ b/test-mocha/common/util/compute_state_display.js
@@ -85,6 +85,20 @@ describe('computeStateDisplay', () => {
assert.strictEqual(computeStateDisplay(altLocalize, stateObj, 'en'), 'state.default.unavailable');
});
+ it('Localizes sensor value with component translation', () => {
+ const altLocalize = function (message, ...args) {
+ if (message !== 'component.sensor.state.custom_state') return null;
+ return localize(message, ...args);
+ };
+ const stateObj = {
+ entity_id: 'sensor.test',
+ state: 'custom_state',
+ attributes: {
+ },
+ };
+ assert.strictEqual(computeStateDisplay(altLocalize, stateObj, 'en'), 'component.sensor.state.custom_state');
+ });
+
it('Localizes input_datetime with full date time', () => {
const stateObj = {
entity_id: 'input_datetime.test',