Skip to content

Commit

Permalink
Merge pull request #24 from nwg-piotr/own-langs
Browse files Browse the repository at this point in the history
Allow own lang files
  • Loading branch information
nwg-piotr authored Sep 24, 2024
2 parents 5ab84d0 + 24fc9f0 commit 5ce3a62
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
29 changes: 27 additions & 2 deletions nwg_hello/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,37 @@
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")
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:
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"))

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))
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:
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))
for key in voc:
if key in loc:
voc[key] = loc[key]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5ce3a62

Please sign in to comment.