-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.py
More file actions
executable file
·90 lines (67 loc) · 1.79 KB
/
Copy pathhello.py
File metadata and controls
executable file
·90 lines (67 loc) · 1.79 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python3
"""Hello World Multi Language.
Dependendo da lingua configurada no ambiente, o programa exibe a mensagem
correspondente.
Como usar:
Tenha a variável LANG devidamente configurada, ex:
export LANG=pt_BR
Ou informe através do CLI argument `--lang`
Ou o usuário terá que digitar.
Execução:
python3 hello.py
ou
./hello.py
"""
__version__ = "0.1.3"
__author__ = "Juliene Trindade"
__license__ = "Unlicense"
import os
import sys
arguments = {"lang": None, "count": 1}
for arg in sys.argv[1:]:
# TODO: Tratar ValueError:
try:
key, value = arg.split("=")
except ValueError as e:
# TODO: Logging
print(f"[ERROR] {str(e)}")
print("You need to use `=`")
print(f"You passed {arg}")
print(f"Try with --key=value")
sys.exit(1)
key = key.lstrip("-").strip()
value = value.strip()
# Validação
if key not in arguments:
print(f"! Invalid Option {key}")
sys.exit()
arguments[key] = value
current_language = arguments["lang"]
if current_language is None:
# TODO: 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 = {
"en_US": "Hello, World!",
"pt_BR": "Olá, Mundo!",
"it_IT": "Ciao, Mondo!",
"es_SP": "Hola, Mundo!",
"fr_FR": "Bonjour, Monde!",
}
"""
# try com valor default
message = msg.get(current_language, msg["en_US"])
"""
# LBYL
try:
message = msg[current_language]
except KeyError as e:
print(f"[ERROR] {str(e)}")
print(f"Language is invalid, choose from: {list(msg.keys())}")
sys.exit(1)
print(
msg[current_language] * int(arguments["count"])
)