Skip to content

Commit 5ac8bf4

Browse files
authored
Update timer.py
1 parent dfcdb82 commit 5ac8bf4

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

timer.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
import subprocess
22
import json
3+
import os
34
from urllib.request import urlopen
5+
from pathlib import Path
46
BASE_URL = 'https://raw.githubusercontent.com/vikdevelop/timer/main/translations/json'
5-
try:
6-
# Czech
7-
if subprocess.getoutput("locale | grep 'LANG'") == 'LANG=cs_CZ.UTF-8':
8-
lang = 'cs.json'
9-
# Italian
10-
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=it_IT.UTF-8':
11-
lang = 'it.json'
12-
# Deutsch
13-
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=de_DE.UTF-8':
14-
lang = 'de.json'
15-
# Russian
16-
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=ru_RU.UTF-8':
17-
lang = 'ru.json'
18-
# Finnish
19-
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=fi_FI.UTF-8':
20-
lang = 'fi.json'
21-
# French
22-
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=fr_FR.UTF-8':
23-
lang = 'fr.json'
24-
# Norwegian (Bokmål)
25-
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=nb_NO.UTF-8':
26-
lang = 'nb_NO.json'
27-
# Ukrainian
28-
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=uk_UA.UTF-8':
29-
lang = 'uk.json'
30-
# Spanish
31-
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=es_ES.UTF-8':
32-
lang = 'es.json'
33-
# English
34-
else:
35-
lang = 'en.json'
36-
# Open Translation from URL
37-
locale = urlopen('{}/{}'.format(BASE_URL, lang))
38-
except OSError:
39-
locale = open(f'/app/translations/{lang}')
7+
# Czech
8+
if subprocess.getoutput("locale | grep 'LANG'") == 'LANG=cs_CZ.UTF-8':
9+
lang = 'cs.json'
10+
# Italian
11+
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=it_IT.UTF-8':
12+
lang = 'it.json'
13+
# Deutsch
14+
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=de_DE.UTF-8':
15+
lang = 'de.json'
16+
# Russian
17+
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=ru_RU.UTF-8':
18+
lang = 'ru.json'
19+
# Finnish
20+
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=fi_FI.UTF-8':
21+
lang = 'fi.json'
22+
# French
23+
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=fr_FR.UTF-8':
24+
lang = 'fr.json'
25+
# Norwegian (Bokmål)
26+
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=nb_NO.UTF-8':
27+
lang = 'nb_NO.json'
28+
# Ukrainian
29+
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=uk_UA.UTF-8':
30+
lang = 'uk.json'
31+
# Spanish
32+
elif subprocess.getoutput("locale | grep 'LANG'") == 'LANG=es_ES.UTF-8':
33+
lang = 'es.json'
34+
# English
35+
else:
36+
lang = 'en.json'
37+
38+
if os.path.exists("{}/.var/app/com.github.vikdevelop.timer/cache/{}".format(Path.home(), lang)):
39+
locale = open("{}/.var/app/com.github.vikdevelop.timer/cache/{}".format(Path.home(), lang))
40+
else:
41+
locale = open(f"/app/translations/{lang}")
4042

4143
# Load JSON local file
4244
jT = json.load(locale)

0 commit comments

Comments
 (0)