forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefinition.py
93 lines (82 loc) · 1.7 KB
/
definition.py
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
91
92
93
# This file defines the special regexes
# list of symbols recognized as characters (with non-Latin characters)
CHARACTER = '[\\p{Lu}\\p{Ll}\\p{Lt}\\p{Lm}\\p{Lo}\\p{Nl}_\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}·]'
# definition of word
WORD = '(' + CHARACTER + "+)"
# space
SPACE = "( +)"
# beginning and end of one line, including space
START_LINE = '(^ *)'
END_LINE = '( *$)'
# beginning and end of words
START_WORD = '(^| )'
END_WORD = '(?!' + CHARACTER + ')'
DIGIT = '[__DIGIT__]'
TRANSLATE_WORDS = [
"define",
"call",
"with",
"def",
"return",
"print",
"ask",
"echo",
"forward",
"turn",
"color",
"black",
"blue",
"brown",
"gray",
"green",
"orange",
"pink",
"purple",
"red",
"white",
"yellow",
"right",
"left",
"is",
"sleep",
"add",
"to_list",
"remove",
"from",
"at",
"random",
"in",
"if",
"else",
"and",
"repeat",
"times",
"for",
"range",
"to",
"step",
"elif",
"input",
"or",
"while",
"length",
"comma",
"pressed",
"clear"
]
TOKEN_CONSTANT = "text"
def get_translated_keyword(word, withoutGroup=False):
""" Function that allows to add double underscores around the keywords to be translated.
The "__" are added before and after only if the keyword belongs to the list.
- withoutGroup : bool, Add parentheses for make a group or not
"""
if withoutGroup:
if word in TRANSLATE_WORDS:
return "__" + word + "__"
else:
return word
else:
if word in TRANSLATE_WORDS:
return "(__" + word + "__)"
else:
return "(" + word + ")"