Skip to content

Commit 77d5c60

Browse files
authored
Merge pull request #55 from etcho/main
Add full support for localization
2 parents 09eb858 + d9dac95 commit 77d5c60

1 file changed

Lines changed: 70 additions & 12 deletions

File tree

transmission-card.js

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,65 @@ const translations = {
1111
"up_down": "Uploading/Downloading",
1212
"seeding": "Seeding",
1313
"downloading": "Downloading"
14-
}
14+
},
15+
"torrent_state": {
16+
"stopped": "Stopped",
17+
"check_pending": "Check Pending",
18+
"checking": "Checking",
19+
"download_pending": "Download Pending",
20+
"downloading": "Downloading",
21+
"seed_pending": "Seed Pending",
22+
"seeding": "Seeding"
23+
},
24+
"torrent_types": {
25+
"total": "All",
26+
"active": "Active",
27+
"completed": "Completed",
28+
"paused": "Paused",
29+
"started": "Started"
30+
},
31+
"torrent_link": "Torrent Link",
32+
"your_magnet_link": "Your magnet link",
33+
"start_all": "Start All",
34+
"stop_all": "Stop All",
35+
"turtle_mode": "Turtle Mode",
36+
"start": "Start",
37+
"stop": "Stop",
38+
"delete": "Delete torrent",
39+
"delete_data": "Delete torrent and data"
40+
},
41+
"pt-BR": {
42+
"sensor_state": {
43+
"idle": "Ocioso",
44+
"up_down": "Semeando/Baixando",
45+
"seeding": "Semeando",
46+
"downloading": "Baixando"
47+
},
48+
"torrent_state": {
49+
"stopped": "Parado",
50+
"check_pending": "Verificação Pendente",
51+
"checking": "Verificando",
52+
"download_pending": "Download Pendente",
53+
"downloading": "Baixando",
54+
"seed_pending": "Semeadura Pendente",
55+
"seeding": "Semeando"
56+
},
57+
"torrent_types": {
58+
"total": "Todos",
59+
"active": "Ativos",
60+
"completed": "Completos",
61+
"paused": "Pausados",
62+
"started": "Iniciados"
63+
},
64+
"torrent_link": "Link do Torrent",
65+
"your_magnet_link": "Seu link magnet",
66+
"start_all": "Iniciar Todos",
67+
"stop_all": "Parar Todos",
68+
"turtle_mode": "Modo Tartaruga",
69+
"start": "Iniciar",
70+
"stop": "Parar",
71+
"delete": "Remover torrent",
72+
"delete_data": "Remover torrent e arquivos"
1573
},
1674
"ru": {
1775
"sensor_state": {
@@ -377,10 +435,10 @@ class TransmissionCard extends LitElement {
377435
`
378436
<div id="addTorrent">
379437
<ha-textfield
380-
placeholder="Your magnet link"
438+
placeholder="${translations[this.hass.config.language]?.your_magnet_link || translations['en'].your_magnet_link}"
381439
name="addTorrent"
382440
@keypress="${this._addTorrent}"
383-
label="Torrent link">
441+
label="${translations[this.hass.config.language]?.torrent_link || translations['en'].torrent_link}">
384442
</ha-textfield>
385443
</div>
386444
`
@@ -400,7 +458,7 @@ class TransmissionCard extends LitElement {
400458
return html`
401459
<div class="torrent">
402460
<div class="torrent_name">${torrent.name}</div>
403-
<div class="torrent_state">${torrent.status}</div>
461+
<div class="torrent_state">${translations[this.hass.config.language]?.torrent_state[torrent.status] || translations['en'].torrent_state[torrent.status] || torrent.status}</div>
404462
<div class="progressbar">
405463
<div class="${torrent.status} progressin" style="width:${torrent.percent}%">
406464
</div>
@@ -421,7 +479,7 @@ class TransmissionCard extends LitElement {
421479
}
422480
const activeTorrentStatus = ['seeding', 'downloading']
423481
const isActive = activeTorrentStatus.includes(torrent.status);
424-
const label = isActive ? 'Stop' : 'Start';
482+
const label = isActive ? translations[this.hass.config.language]?.stop || translations['en'].stop : translations[this.hass.config.language]?.start || translations['en'].start;
425483
const icon = isActive ? 'mdi:stop' : 'mdi:play';
426484

427485
return html`
@@ -450,7 +508,7 @@ class TransmissionCard extends LitElement {
450508
return html``;
451509
}
452510

453-
const label = deleteData ? 'Delete with data' : 'Delete';
511+
const label = deleteData ? translations[this.hass.config.language]?.delete_data || translations['en'].delete_data : translations[this.hass.config.language]?.delete || translations['en'].delete;
454512
const icon = deleteData ? 'mdi:delete' : 'mdi:close';
455513

456514
return html`
@@ -525,7 +583,7 @@ class TransmissionCard extends LitElement {
525583
<ha-icon-button
526584
class="turtle_${state}"
527585
@click="${this._toggleTurtle}"
528-
title="turtle mode"
586+
title="${translations[this.hass.config.language]?.turtle_mode || translations['en'].turtle_mode}"
529587
id="turtle">
530588
<ha-icon icon="mdi:turtle"></ha-icon>
531589
</ha-icon-button>
@@ -545,7 +603,7 @@ class TransmissionCard extends LitElement {
545603
const state = this.hass.states[this.switch_entity_id].state;
546604
const isOn = state === 'on';
547605
const icon = isOn ? 'mdi:stop' : 'mdi:play';
548-
const title = isOn ? 'Stop All' : 'Play All';
606+
const title = isOn ? translations[this.hass.config.language]?.stop_all || translations['en'].stop_all : translations[this.hass.config.language]?.start_all || translations['en'].start_all;
549607
return html`
550608
<div class="titleitem">
551609
<ha-icon-button
@@ -587,9 +645,9 @@ class TransmissionCard extends LitElement {
587645
naturalMenuWidth
588646
>
589647
${torrent_types.map(
590-
(type) => html`
591-
<mwc-list-item .value=${type}>${type}</mwc-list-item>`
592-
)}
648+
(type) => html`
649+
<mwc-list-item .value=${type}>${translations[this.hass.config.language]?.torrent_types[type] || translations['en'].torrent_types[type] || type}</mwc-list-item>`
650+
)}
593651
</ha-select>
594652
</div>
595653
`;
@@ -844,4 +902,4 @@ if (!customElements.get('transmission-card')) {
844902
name: 'Transmission Card',
845903
preview: true,
846904
description: 'This Lovelace custom card displays torrents information provided by the Transmission Integration.',
847-
});
905+
});

0 commit comments

Comments
 (0)