Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"editor": {
"name": "Name (Optional)",
"entity": "Entity",
"remote": "Remote (Optional)",
"theme": "Theme (Optional)",
"roku_tv": "Roku TV?",
"yaml_hint": "Use the YAML editor if you need to specify custom services"
},
"keys": {
"power": "Power",
"volume_up": "Volume Up",
"volume_down": "Volume Down",
"volume_mute": "Mute",
"return": "Return",
"source": "Source",
"info": "Info",
"home": "Home",
"channel_up": "Channel Up",
"channel_down": "Channel Down",
"up": "Up",
"left": "Left",
"enter": "Enter",
"right": "Right",
"down": "Down",
"rewind": "Rewind",
"play": "Play",
"pause": "Pause",
"fast_forward": "Fast Forward"
},
"sources": {
"netflix": "Netflix",
"spotify": "Spotify",
"youtube": "YouTube"
}
}
36 changes: 36 additions & 0 deletions translations/tr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"editor": {
"name": "Ad (İsteğe Bağlı)",
"entity": "Varlık",
"remote": "Uzaktan Kumanda (İsteğe Bağlı)",
"theme": "Tema (İsteğe Bağlı)",
"roku_tv": "Roku TV?",
"yaml_hint": "Özel servisler belirtmek için YAML editörünü kullanın"
},
"keys": {
"power": "Güç",
"volume_up": "Ses Aç",
"volume_down": "Ses Kıs",
"volume_mute": "Sessiz",
"return": "Geri",
"source": "Kaynak",
"info": "Bilgi",
"home": "Ana Sayfa",
"channel_up": "Kanal Yukarı",
"channel_down": "Kanal Aşağı",
"up": "Yukarı",
"left": "Sol",
"enter": "Tamam",
"right": "Sağ",
"down": "Aşağı",
"rewind": "Geri Sar",
"play": "Oynat",
"pause": "Duraklat",
"fast_forward": "İleri Sar"
},
"sources": {
"netflix": "Netflix",
"spotify": "Spotify",
"youtube": "YouTube"
}
}
47 changes: 41 additions & 6 deletions tv-card-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,41 @@ const LitElement = Object.getPrototypeOf(
);
const html = LitElement.prototype.html;

// Translations for editor
const editorTranslations = {
"en": {
"name": "Name (Optional)",
"entity": "Entity",
"remote": "Remote (Optional)",
"theme": "Theme (Optional)",
"roku_tv": "Roku TV?",
"yaml_hint": "Use the YAML editor if you need to specify custom services"
},
"tr": {
"name": "Ad (İsteğe Bağlı)",
"entity": "Varlık",
"remote": "Uzaktan Kumanda (İsteğe Bağlı)",
"theme": "Tema (İsteğe Bağlı)",
"roku_tv": "Roku TV?",
"yaml_hint": "Özel servisler belirtmek için YAML editörünü kullanın"
}
};

// Helper function to get current language for editor
function getEditorLanguage(hass) {
if (!hass) return "en";
const lang = hass.selectedLanguage || hass.language || "en";
const langCode = lang.substring(0, 2).toLowerCase();
return editorTranslations[langCode] ? langCode : "en";
}

// Helper function to get editor translation
function te(hass, key) {
const lang = getEditorLanguage(hass);
const langData = editorTranslations[lang] || editorTranslations["en"];
return langData[key] || editorTranslations["en"][key] || key;
}

export class TVCardEditor extends LitElement {
setConfig(config) {
this._config = config;
Expand Down Expand Up @@ -73,13 +108,13 @@ export class TVCardEditor extends LitElement {
<div class="card-config">
<div class="side-by-side">
<paper-input
label="Name (Optional)"
label="${te(this.hass, "name")}"
.value="${this._name}"
.configValue="${"name"}"
@value-changed="${this._valueChanged}"
></paper-input>
<paper-dropdown-menu
label="Entity"
label="${te(this.hass, "entity")}"
@value-changed="${this._valueChanged}"
.configValue="${"entity"}"
>
Expand All @@ -99,7 +134,7 @@ export class TVCardEditor extends LitElement {
</div>
<div class="side-by-side">
<paper-dropdown-menu
label="Remote (Optional)"
label="${te(this.hass, "remote")}"
@value-changed="${this._valueChanged}"
.configValue="${"remote"}"
>
Expand All @@ -118,7 +153,7 @@ export class TVCardEditor extends LitElement {
</paper-dropdown-menu>

<paper-dropdown-menu
label="Theme (Optional)"
label="${te(this.hass, "theme")}"
@value-changed="${this._valueChanged}"
.configValue="${"theme"}"
>
Expand All @@ -139,10 +174,10 @@ export class TVCardEditor extends LitElement {
?checked="${this._tv !== false}"
.configValue="${"tv"}"
@change="${this._valueChanged}"
>Roku TV?</paper-toggle-button
>${te(this.hass, "roku_tv")}</paper-toggle-button
>
</div>
<div>Use the YAML editor if you need to specify custom services</div>
<div>${te(this.hass, "yaml_hint")}</div>
</div>
`;
}
Expand Down
103 changes: 102 additions & 1 deletion tv-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,105 @@ const LitElement = Object.getPrototypeOf(
);
const html = LitElement.prototype.html;

// Translations object - embedded for reliability
const translations = {
"en": {
"editor": {
"name": "Name (Optional)",
"entity": "Entity",
"remote": "Remote (Optional)",
"theme": "Theme (Optional)",
"roku_tv": "Roku TV?",
"yaml_hint": "Use the YAML editor if you need to specify custom services"
},
"keys": {
"power": "Power",
"volume_up": "Volume Up",
"volume_down": "Volume Down",
"volume_mute": "Mute",
"return": "Return",
"source": "Source",
"info": "Info",
"home": "Home",
"channel_up": "Channel Up",
"channel_down": "Channel Down",
"up": "Up",
"left": "Left",
"enter": "Enter",
"right": "Right",
"down": "Down",
"rewind": "Rewind",
"play": "Play",
"pause": "Pause",
"fast_forward": "Fast Forward"
},
"sources": {
"netflix": "Netflix",
"spotify": "Spotify",
"youtube": "YouTube"
}
},
"tr": {
"editor": {
"name": "Ad (İsteğe Bağlı)",
"entity": "Varlık",
"remote": "Uzaktan Kumanda (İsteğe Bağlı)",
"theme": "Tema (İsteğe Bağlı)",
"roku_tv": "Roku TV?",
"yaml_hint": "Özel servisler belirtmek için YAML editörünü kullanın"
},
"keys": {
"power": "Güç",
"volume_up": "Ses Aç",
"volume_down": "Ses Kıs",
"volume_mute": "Sessiz",
"return": "Geri",
"source": "Kaynak",
"info": "Bilgi",
"home": "Ana Sayfa",
"channel_up": "Kanal Yukarı",
"channel_down": "Kanal Aşağı",
"up": "Yukarı",
"left": "Sol",
"enter": "Tamam",
"right": "Sağ",
"down": "Aşağı",
"rewind": "Geri Sar",
"play": "Oynat",
"pause": "Duraklat",
"fast_forward": "İleri Sar"
},
"sources": {
"netflix": "Netflix",
"spotify": "Spotify",
"youtube": "YouTube"
}
}
};

// Helper function to get current language
function getLanguage(hass) {
if (!hass) return "en";
const lang = hass.selectedLanguage || hass.language || "en";
// Return language code (first 2 chars) if full locale provided
const langCode = lang.substring(0, 2).toLowerCase();
return translations[langCode] ? langCode : "en";
}

// Helper function to get translation
function t(hass, category, key) {
const lang = getLanguage(hass);
const langData = translations[lang] || translations["en"];
if (langData[category] && langData[category][key]) {
return langData[category][key];
}
// Fallback to English
if (translations["en"][category] && translations["en"][category][key]) {
return translations["en"][category][key];
}
return key;
}

const keys = {
"power": {"key": "KEY_POWER", "icon": "mdi:power"},
"volume_up": {"key": "KEY_VOLUP", "icon": "mdi:volume-plus"},
Expand Down Expand Up @@ -267,12 +366,14 @@ class TVCardServices extends LitElement {
let button_info = this.custom_keys[action] || this.custom_sources[action] || keys[action] || sources[action] || {};
let icon = button_info.icon;
let custom_svg_path = this.custom_icons[icon];
// Get translated title for the button
let buttonTitle = t(this._hass, "keys", action) || t(this._hass, "sources", action) || action;

return html`
<ha-icon-button
.action="${action}"
@click="${this.handleActionClick}"
title="${action}"
title="${buttonTitle}"
.path="${custom_svg_path ? custom_svg_path : ""}"
>
<ha-icon
Expand Down