Commit 791d340f authored by Elena Grandi's avatar Elena Grandi
Browse files

Migrated set-session-language from fuss-client

parent 46307a0d
[Desktop Entry]
Type=Application
Encoding=UTF-8
Exec=set-session-language
Name=Set Language for Next Session
Terminal=False
Categories=Settings;
#!/usr/bin/env python3
import os.path
import subprocess
import tkinter as tk
from gettext import gettext as _
class App(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master.title(_("Set session locale"))
self.chosen_locale = tk.StringVar(self)
self.find_locales()
self.pack()
self.create_widgets()
def find_locales(self):
res = locales = subprocess.run(
['locale', '-a'],
stdout=subprocess.PIPE,
)
self.locales = []
for l in res.stdout.split(b'\n'):
if b'utf8' in l:
self.locales.append(l.decode())
def create_widgets(self):
self.text = tk.Label(
self,
text=_("Select the locale for your future sessions.")
)
self.text.pack(side="top")
self.chosen_locale.set(self.locales[0])
self.locale_menu = tk.OptionMenu(self, self.chosen_locale, *self.locales)
self.locale_menu.pack(side="top")
self.set_button = tk.Button(self)
self.set_button['text'] = "Set locale"
self.set_button['command'] = self.set_locale
self.set_button.pack(side="bottom")
def set_locale(self):
dmfname = os.path.expanduser('~/.dmrc')
lines = []
try:
with open(dmfname, 'r') as fp:
not_found = True
for l in fp.readlines():
if l.startswith('Language'):
lines.append(
"Language={l}\n".format(l=self.chosen_locale.get())
)
not_found = False
else:
lines.append(l)
if not_found:
lines.append(
"Language={l}\n".format(l=self.chosen_locale.get())
)
except FileNotFoundError:
lines = [
"[Desktop]\n",
"Language={l}\n".format(l=self.chosen_locale.get()),
]
with open(dmfname, 'w') as wfp:
for l in lines:
wfp.write(l)
root.destroy()
root = tk.Tk()
app = App(master=root)
app.mainloop()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment