-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.py
More file actions
executable file
·70 lines (47 loc) · 1.17 KB
/
hello.py
File metadata and controls
executable file
·70 lines (47 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
"""Hello world multi linguas
Exibe a mensagem no idioma configurado da variável de ambiente.
Como usar:
Tenha a variavel LANG devidamente configurada:
export LANG=pt_BR
Execucao:
python3 hello.py
ou
./hello.py
"""
__version__ = "0.1.3"
__author__ = "Marcelo Garcia"
__licensa__ = "Unlicense"
import os
import sys
sys_argv = sys.argv[1:]
#definindo argumentos que o programa espera receber
arguments = {
"lang": None,
"count": 1,
}
for arg in sys_argv:
#TO DO: tratar ValueError
key, value = arg.split("=")
key = key.lstrip("-").strip()
value = value.strip()
if key not in arguments:
print(f"'{key}': Invalid options")
sys.exit() #para a execução do programa
arguments[key]=value
current_language = arguments["lang"]
if current_language is None:
#TO DO: usar repetição
if "LANG" in os.environ:
current_language = os.getenv("LANG")
else:
current_language = input("Choose a language: ")
current_language = current_language[:5]
msg = {
"pt_BR": "Olá, mundo!",
"it_IT": "Caio, mundo!",
"es_SP": "Hola, mundo!",
"fr_FR": "Bonjur, mode!",
"en_US": "Hello, world!",
}
print(msg[current_language] * int(arguments["count"]))