mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-23 16:04:25 +01:00
fix path
This commit is contained in:
@@ -14,13 +14,14 @@ def build_locale_filestring(locale):
|
|||||||
locale = locale.split("_")[0]
|
locale = locale.split("_")[0]
|
||||||
|
|
||||||
filename = f"{locale}.json"
|
filename = f"{locale}.json"
|
||||||
path_frontend_file = os.path.join(os.getcwd(), "translations", "frontend", filename)
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
path_backend_file = os.path.join(os.getcwd(), "translations", "backend" , filename)
|
path_frontend_file = os.path.join(dir_path, "translations", "frontend", filename)
|
||||||
|
path_backend_file = os.path.join(dir_path, "translations", "backend" , filename)
|
||||||
return path_frontend_file, path_backend_file
|
return path_frontend_file, path_backend_file
|
||||||
|
|
||||||
def lookup(path_frontend_file, path_backend_file, lookupstr):
|
def lookup(path_frontend_file, path_backend_file, lookupstr):
|
||||||
if not (os.path.exists(path_frontend_file) and os.path.exists(path_backend_file)):
|
if not (os.path.exists(path_frontend_file) and os.path.exists(path_backend_file)):
|
||||||
return "error"
|
return "error_fnf"
|
||||||
with open(path_frontend_file, 'r') as f, open(path_backend_file, 'r') as b:
|
with open(path_frontend_file, 'r') as f, open(path_backend_file, 'r') as b:
|
||||||
translations = { "frontend": json.load(f), "backend": json.load(b)}
|
translations = { "frontend": json.load(f), "backend": json.load(b)}
|
||||||
res = translations
|
res = translations
|
||||||
@@ -28,13 +29,13 @@ def lookup(path_frontend_file, path_backend_file, lookupstr):
|
|||||||
if k in res:
|
if k in res:
|
||||||
res = res[k]
|
res = res[k]
|
||||||
if type(res) is not str:
|
if type(res) is not str:
|
||||||
res = "error"
|
res = "error_tnf"
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def get_translation(locale, lookupstr):
|
def get_translation(locale, lookupstr):
|
||||||
path_frontend_file, path_backend_file = build_locale_filestring(locale)
|
path_frontend_file, path_backend_file = build_locale_filestring(locale)
|
||||||
res = lookup(path_frontend_file, path_backend_file, lookupstr)
|
res = lookup(path_frontend_file, path_backend_file, lookupstr)
|
||||||
if res == "error":
|
if res.startswith("error"):
|
||||||
path_frontend_file, path_backend_file = build_locale_filestring("en_US")
|
path_frontend_file, path_backend_file = build_locale_filestring("en_US")
|
||||||
res = lookup(path_frontend_file, path_backend_file, lookupstr)
|
res = lookup(path_frontend_file, path_backend_file, lookupstr)
|
||||||
return res
|
return res
|
||||||
|
|||||||
Reference in New Issue
Block a user