From b9cf85b9a1c9ce6cc8e3273416387eb8fdd2d260 Mon Sep 17 00:00:00 2001 From: piotr Date: Tue, 24 Sep 2024 01:22:15 +0200 Subject: [PATCH 1/5] allow user-defined lang files #19 --- nwg_hello/main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/nwg_hello/main.py b/nwg_hello/main.py index b168eb7..c2468ad 100755 --- a/nwg_hello/main.py +++ b/nwg_hello/main.py @@ -107,12 +107,23 @@ client = None # Load vocabulary -voc = load_json(os.path.join(dir_name, "langs", "en_US")) +if os.path.isfile("/etc/nwg-hello/en_US"): + # allow user-defined basic lang file in /etc/nwg-hello #19 + voc = load_json("/etc/nwg-hello/en_US") +else: + # load predefined basic lang file + voc = load_json(os.path.join(dir_name, "langs", "en_US")) + user_locale = locale.getlocale()[0] if not settings["lang"] else settings["lang"] # translate if necessary (and if we have a translation) if user_locale != "en_US" and user_locale in os.listdir(os.path.join(dir_name, "langs")): # translated phrases - loc = load_json(os.path.join(dir_name, "langs", user_locale)) + if os.path.isfile(os.path.join("/etc/nwg-hello", user_locale)): + # allow user-defined lang files in /etc/nwg-hello #19 + loc = load_json(os.path.join("/etc/nwg-hello", user_locale)) + else: + # load predefined lang file + loc = load_json(os.path.join(dir_name, "langs", user_locale)) for key in voc: if key in loc: voc[key] = loc[key] From 68b6458cac07479006a1278ad9f124594991fdda Mon Sep 17 00:00:00 2001 From: piotr Date: Tue, 24 Sep 2024 01:35:38 +0200 Subject: [PATCH 2/5] bump to 0.2.4 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5c95fa7..a90fe7b 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ def read(f_name): setup( name='nwg-hello', - version='0.2.3', + version='0.2.4', description='GTK3-based greeter for greetd', packages=find_packages(), include_package_data=True, From c3b1a6564b428bcb29d24b03e918e8d0ac0c9c20 Mon Sep 17 00:00:00 2001 From: piotr Date: Tue, 24 Sep 2024 02:12:11 +0200 Subject: [PATCH 3/5] improve error handling --- README.md | 8 ++++++++ nwg_hello/main.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index cdee916..f067615 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,14 @@ Copy `/etc/nwg-hello/nwg-hello-default.css` to `/etc/nwg-hello/nwg-hello.css` an If you'd like to use own icons, do not replace `/usr/share/nwg-hello/*-default.svg` files. Place your `poweroff.svg`, `reboot.svg` and `sleep.svg` files in the same directory. +## Own language files + +You can't translate labels in the .glade file, as the program replaces the values with what's defined in +[language files](https://github.com/nwg-piotr/nwg-hello/tree/main/nwg_hello/langs). Since the 0.2.4 version, however, +you can copy your lang file to `/etc/nwg-hello/` and make desired changes there, +see https://github.com/nwg-piotr/nwg-hello/issues/19. Be careful with syntax, the JSON format is unforgiving. +Test your lang file by running `nwg-hello -t -d` from terminal. + ## Running on Debian and labwc Submitted by [@01micko](https://github.com/01micko). diff --git a/nwg_hello/main.py b/nwg_hello/main.py index c2468ad..dfb0d4f 100755 --- a/nwg_hello/main.py +++ b/nwg_hello/main.py @@ -110,6 +110,9 @@ if os.path.isfile("/etc/nwg-hello/en_US"): # allow user-defined basic lang file in /etc/nwg-hello #19 voc = load_json("/etc/nwg-hello/en_US") + if not voc: + eprint(f"Could not load /etc/nwg-hello/en_US, loading default file instead.") + voc = load_json(os.path.join(dir_name, "langs", "en_US")) else: # load predefined basic lang file voc = load_json(os.path.join(dir_name, "langs", "en_US")) @@ -121,6 +124,9 @@ if os.path.isfile(os.path.join("/etc/nwg-hello", user_locale)): # allow user-defined lang files in /etc/nwg-hello #19 loc = load_json(os.path.join("/etc/nwg-hello", user_locale)) + if not loc: + eprint(f"Could not load {os.path.join('/etc/nwg-hello', user_locale)}, loading default file instead.") + loc = load_json(os.path.join(dir_name, "langs", user_locale)) else: # load predefined lang file loc = load_json(os.path.join(dir_name, "langs", user_locale)) From 361826ef69507fec89eb211334d871c3fda8c109 Mon Sep 17 00:00:00 2001 From: piotr Date: Tue, 24 Sep 2024 02:17:40 +0200 Subject: [PATCH 4/5] more comments --- nwg_hello/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nwg_hello/main.py b/nwg_hello/main.py index dfb0d4f..d3ce5d3 100755 --- a/nwg_hello/main.py +++ b/nwg_hello/main.py @@ -111,6 +111,7 @@ # allow user-defined basic lang file in /etc/nwg-hello #19 voc = load_json("/etc/nwg-hello/en_US") if not voc: + # couldn't load json! eprint(f"Could not load /etc/nwg-hello/en_US, loading default file instead.") voc = load_json(os.path.join(dir_name, "langs", "en_US")) else: @@ -125,6 +126,7 @@ # allow user-defined lang files in /etc/nwg-hello #19 loc = load_json(os.path.join("/etc/nwg-hello", user_locale)) if not loc: + # couldn't load json! eprint(f"Could not load {os.path.join('/etc/nwg-hello', user_locale)}, loading default file instead.") loc = load_json(os.path.join(dir_name, "langs", user_locale)) else: From 24fc9f0cbce28dcd91641a3bf18f513d41e8daea Mon Sep 17 00:00:00 2001 From: piotr Date: Tue, 24 Sep 2024 02:32:39 +0200 Subject: [PATCH 5/5] add debug messages --- nwg_hello/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nwg_hello/main.py b/nwg_hello/main.py index d3ce5d3..b96af77 100755 --- a/nwg_hello/main.py +++ b/nwg_hello/main.py @@ -114,6 +114,9 @@ # couldn't load json! eprint(f"Could not load /etc/nwg-hello/en_US, loading default file instead.") voc = load_json(os.path.join(dir_name, "langs", "en_US")) + else: + if args.debug: + eprint(f"Using /etc/nwg-hello/en_US lang file") else: # load predefined basic lang file voc = load_json(os.path.join(dir_name, "langs", "en_US")) @@ -129,6 +132,9 @@ # couldn't load json! eprint(f"Could not load {os.path.join('/etc/nwg-hello', user_locale)}, loading default file instead.") loc = load_json(os.path.join(dir_name, "langs", user_locale)) + else: + if args.debug: + eprint(f"Using /etc/nwg-hello/{user_locale} lang file") else: # load predefined lang file loc = load_json(os.path.join(dir_name, "langs", user_locale))