Coverage for rollnjump/lang.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Roll 'n' Jump
2# Written in 2020, 2021 by Samuel Arsac, Hugo Buscemi,
3# Matteo Chencerel, Rida Lali
4# To the extent possible under law, the author(s) have dedicated all
5# copyright and related and neighboring rights to this software to the
6# public domain worldwide. This software is distributed without any warranty.
7# You should have received a copy of the CC0 Public Domain Dedication along
8# with this software. If not, see
9# <http://creativecommons.org/publicdomain/zero/1.0/>.
11"""Gestion de la langue."""
13from os.path import join
14import rollnjump.utilities as ut
15import rollnjump.conf as cf
16from rollnjump.conf import State
17import rollnjump.menu as mn
19FILE = join(cf.CONFDIR, "lang.txt")
20"""Fichier de langue."""
21AVAILABLE = ["fr", "en"]
22"""Langues disponibles."""
25def init_lang():
26 """Initialiser le fichier lang.txt."""
27 with open(FILE, "w") as empty_lang:
28 empty_lang.write(cf.LANG)
31def get_lang():
32 """Récupère la langue choisie par l'utilisateur."""
33 with open(FILE) as lg:
34 lang = lg.readlines()
35 if len(lang) > 0 and ut.onlyalphanum(lang[0]) in AVAILABLE:
36 cf.LANG = ut.onlyalphanum(lang[0])
37 changbuttonslang(cf.LANG)
38 else:
39 cf.STATE = State.languages
40 cf.LANG = ""
43def set_lang(lang):
44 """
45 Change la langue du jeu.
47 Parameters
48 ----------
49 lang : str
50 Langue choisie par l'utilisateur
51 """
52 cf.LANG = ut.onlyalphanum(lang)
53 changbuttonslang(cf.LANG)
54 with open(FILE, "w") as empty_lang:
55 empty_lang.write(cf.LANG)
58def changbuttonslang(lang):
59 """
60 Change l'ensemble des boutons après avoir changé la langue.
62 Parameters
63 ----------
64 lang : str
65 Langue à mettre
66 """
67 mn.restart_button.changlang(lang)
68 mn.language_button.changlang(lang)
69 mn.commands_button.changlang(lang)
70 mn.start_button.changlang(lang)