Localize notification toasts (#1243)

* Localize notification toasts

* Use correct placeholder syntax

* Lint

* Use original string
This commit is contained in:
c727 2018-06-01 16:07:33 +02:00 committed by Paulus Schoutsen
parent c3d67133c2
commit fa11fbc85d
3 changed files with 33 additions and 9 deletions

View File

@ -9,6 +9,8 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { setPassiveTouchGestures } from '@polymer/polymer/lib/utils/settings.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import LocalizeMixin from '../mixins/localize-mixin.js';
import {
ERR_INVALID_AUTH,
subscribeEntities,
@ -46,7 +48,7 @@ window.removeInitMsg = function () {
}
};
class HomeAssistant extends PolymerElement {
class HomeAssistant extends LocalizeMixin(PolymerElement) {
static get template() {
return html`
<ha-pref-storage hass="[[hass]]" id="storage"></ha-pref-storage>
@ -182,23 +184,36 @@ class HomeAssistant extends PolymerElement {
conn.callService(domain, service, serviceData || {})
.then(
() => {
var message;
var name;
let message;
let name;
if (serviceData.entity_id && this.hass.states &&
this.hass.states[serviceData.entity_id]) {
name = computeStateName(this.hass.states[serviceData.entity_id]);
}
if (service === 'turn_on' && serviceData.entity_id) {
message = 'Turned on ' + (name || serviceData.entity_id) + '.';
message = this.localize(
'ui.notification_toast.entity_turned_on',
'entity', name || serviceData.entity_id
);
} else if (service === 'turn_off' && serviceData.entity_id) {
message = 'Turned off ' + (name || serviceData.entity_id) + '.';
message = this.localize(
'ui.notification_toast.entity_turned_off',
'entity', name || serviceData.entity_id
);
} else {
message = 'Service ' + domain + '/' + service + ' called.';
message = this.localize(
'ui.notification_toast.service_called',
'service', `${domain}/${service}`
);
}
notifications.showNotification(message);
},
function () {
notifications.showNotification('Failed to call service ' + domain + '/' + service);
const msg = this.localize(
'ui.notification_toast.service_call_failed',
'service', `${domain}/${service}`
);
notifications.showNotification(msg);
return Promise.reject();
}
),

View File

@ -2,7 +2,9 @@ import '@polymer/paper-toast/paper-toast.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
class NotificationManager extends PolymerElement {
import LocalizeMixin from '../mixins/localize-mixin.js';
class NotificationManager extends LocalizeMixin(PolymerElement) {
static get template() {
return html`
<style>
@ -12,7 +14,7 @@ class NotificationManager extends PolymerElement {
</style>
<paper-toast id="toast" text="[[_text]]" no-cancel-on-outside-click="[[_cancelOnOutsideClick]]"></paper-toast>
<paper-toast id="connToast" duration="0" text="Connection lost. Reconnecting…" opened="[[connectionLost]]"></paper-toast>
<paper-toast id="connToast" duration="0" text="[[localize('ui.notification_toast.connection_lost')]]" opened="[[connectionLost]]"></paper-toast>
`;
}

View File

@ -398,6 +398,13 @@
"remember": "Remember",
"log_in": "Log in"
},
"notification_toast": {
"entity_turned_on": "Turned on {entity}.",
"entity_turned_off": "Turned off {entity}.",
"service_called": "Service {service} called.",
"service_call_failed": "Failed to call service {service}.",
"connection_lost": "Connection lost. Reconnecting…"
},
"sidebar": {
"developer_tools": "Developer tools",
"log_out": "Log out"