diff --git a/src/components/groupList.js b/src/components/groupList.js
index f2cd851..f9b830b 100755
--- a/src/components/groupList.js
+++ b/src/components/groupList.js
@@ -1,11 +1,14 @@
import { LitElement, html, css } from 'lit-element';
+import t from '../utils/translation';
+
import './groupItem';
import './button';
class MiniMediaPlayerGroupList extends LitElement {
static get properties() {
return {
+ hass: {},
entities: {},
player: {},
visible: Boolean,
@@ -39,22 +42,22 @@ class MiniMediaPlayerGroupList extends LitElement {
const { id } = this.player;
return html`
-
Group speakers
+
${t(this.hass, 'title.speaker_management')}
${this.entities.map(item => this.renderItem(item, id))}
this.player.handleGroupChange(e, id, false)}>
- Leave
+ ${t(this.hass, 'label.leave')}
${isGrouped && isMaster ? html`
this.player.handleGroupChange(e, group, false)}>
- Ungroup
+ ${t(this.hass, 'label.ungroup')}
` : html``}
this.player.handleGroupChange(e, this.entities.map(item => item.entity_id), true)}>
- Group all
+ ${t(this.hass, 'label.group_all')}
diff --git a/src/components/powerstrip.js b/src/components/powerstrip.js
index a5e1669..765cd08 100755
--- a/src/components/powerstrip.js
+++ b/src/components/powerstrip.js
@@ -7,7 +7,7 @@ import './mediaControls';
import { ICON } from '../const';
import sharedStyle from '../sharedStyle';
-import getLabel from '../utils/getLabel';
+import t from '../utils/translation';
class MiniMediaPlayerPowerstrip extends LitElement {
static get properties() {
@@ -60,7 +60,7 @@ class MiniMediaPlayerPowerstrip extends LitElement {
if (this.player.isUnavailable)
return html`
- ${getLabel(this.hass, 'state.default.unavailable', 'Unavailable')}
+ ${t(this.hass, 'state.unavailable', 'state.default.unavailable')}
`;
@@ -115,7 +115,7 @@ class MiniMediaPlayerPowerstrip extends LitElement {
else
return html`
- ${getLabel(this.hass, 'state.media_player.idle', 'Idle')}
+ ${t(this.hass, 'state.idle', 'state.media_player.idle')}
`;
}
diff --git a/src/components/tts.js b/src/components/tts.js
index a41bae3..7a17ec2 100755
--- a/src/components/tts.js
+++ b/src/components/tts.js
@@ -1,6 +1,6 @@
import { LitElement, html, css } from 'lit-element';
-import getLabel from '../utils/getLabel';
+import t from '../utils/translation';
class MiniMediaPlayerTts extends LitElement {
static get properties() {
@@ -12,7 +12,7 @@ class MiniMediaPlayerTts extends LitElement {
}
get label() {
- return getLabel(this.hass, 'ui.card.media_player.text_to_speak', 'Say');
+ return t(this.hass, 'placeholder.tts', 'ui.card.media_player.text_to_speak', 'Say');
}
get input() {
@@ -31,7 +31,7 @@ class MiniMediaPlayerTts extends LitElement {
@click=${e => e.stopPropagation()}>
- SEND
+ ${t(this.hass, 'label.send')}
`;
}
diff --git a/src/main.js b/src/main.js
index e8b5326..3ee6ac9 100755
--- a/src/main.js
+++ b/src/main.js
@@ -228,6 +228,7 @@ class MiniMediaPlayer extends LitElement {
` : ''}
diff --git a/src/translations.js b/src/translations.js
new file mode 100644
index 0000000..c0e7e6b
--- /dev/null
+++ b/src/translations.js
@@ -0,0 +1,24 @@
+// Add additional languages with their ISO 639-1 language code
+
+const translations = {
+ en: {
+ placeholder: {
+ tts: 'Text to speak',
+ },
+ label: {
+ leave: 'Leave',
+ ungroup: 'Ungroup',
+ group_all: 'Group all',
+ send: 'Send',
+ },
+ state: {
+ idle: 'Idle',
+ unavailable: 'Unavailable',
+ },
+ title: {
+ speaker_management: 'Group management',
+ },
+ },
+};
+
+export default translations;
diff --git a/src/utils/getLabel.js b/src/utils/getLabel.js
deleted file mode 100755
index 1f46bc9..0000000
--- a/src/utils/getLabel.js
+++ /dev/null
@@ -1,7 +0,0 @@
-const getLabel = (hass, label, fallback = 'unknown') => {
- const lang = hass.selectedLanguage || hass.language;
- const resources = hass.resources[lang];
- return (resources && resources[label] ? resources[label] : fallback);
-};
-
-export default getLabel;
diff --git a/src/utils/translation.js b/src/utils/translation.js
new file mode 100644
index 0000000..41bad9a
--- /dev/null
+++ b/src/utils/translation.js
@@ -0,0 +1,15 @@
+import translations from '../translations';
+
+const DEFAULT_LANG = 'en';
+
+const getNestedProp = (obj, path) => path.split('.').reduce((p, c) => p && p[c] || null, obj);
+
+const translation = (hass, label, hassLabel = undefined, fallback = 'unknown') => {
+ const lang = hass.selectedLanguage || hass.language;
+ return translations[lang] && getNestedProp(translations[lang], label)
+ || hass.resources[lang] && hass.resources[lang][hassLabel]
+ || getNestedProp(translations[DEFAULT_LANG], label)
+ || fallback;
+};
+
+export default translation;