diff --git a/translations/en.json b/translations/en.json new file mode 100644 index 0000000..14da961 --- /dev/null +++ b/translations/en.json @@ -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" + } +} diff --git a/translations/tr.json b/translations/tr.json new file mode 100644 index 0000000..5389404 --- /dev/null +++ b/translations/tr.json @@ -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" + } +} diff --git a/tv-card-editor.js b/tv-card-editor.js index ea21a80..f3edad9 100644 --- a/tv-card-editor.js +++ b/tv-card-editor.js @@ -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; @@ -73,13 +108,13 @@ export class TVCardEditor extends LitElement {
@@ -99,7 +134,7 @@ export class TVCardEditor extends LitElement {
@@ -118,7 +153,7 @@ export class TVCardEditor extends LitElement { @@ -139,10 +174,10 @@ export class TVCardEditor extends LitElement { ?checked="${this._tv !== false}" .configValue="${"tv"}" @change="${this._valueChanged}" - >Roku TV?${te(this.hass, "roku_tv")}
-
Use the YAML editor if you need to specify custom services
+
${te(this.hass, "yaml_hint")}
`; } diff --git a/tv-card.js b/tv-card.js index ec0e755..26e250a 100644 --- a/tv-card.js +++ b/tv-card.js @@ -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"}, @@ -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`