-
Notifications
You must be signed in to change notification settings - Fork 1
/
quotes_and_brackets.py
197 lines (186 loc) · 8.1 KB
/
quotes_and_brackets.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
def get_quotes (lang='all', level='primary'):
"""Get quotation marks used in a particular language.
str `lang` - ISO code of the language, default - "all",
meaning that all quotation marks should be returned;
str `level` - level of quotation marks to be returned, two options:
- "primary" - primary quotation marks (default);
- "secondary" - quotation marks used inside the primary quotation marks;
return set/list - set of all quotation marks if `lang` equals "all",
list of tuples, each tuple is of lenth 2, containing opening and closing
quotation marks.
The source of the quotation marks is Wikipedia:
https://en.wikipedia.org/wiki/Quotation_mark#Summary_table
"""
if lang == 'all':
return set('«»"\'<>‹›„“‚‘’⹂”「」『』﹃﹄﹁﹂《》〈〉⟪⟫⟨⟩❝❞❛❜〝〞〟❮❯')
if level == 'primary':
match lang:
case 'af' | 'nl':
return [('“', '”'), ('„', '”')]
case 'ar':
return [('«', '»'), ('”', '“')]
case 'hy' | 'el' | 'fa' | 'io' | 'kk' | 'km' | 'ps' | 'rm' | 'ug':
return [('«', '»')]
case 'am' | 'ca' | 'es' | 'eu' | 'gl' | 'it' | 'oc' | 'qu' | 'ru' | 'ti':
return [('«', '»'), ('“', '”')]
case 'az' | 'be' | 'no' | 'uz':
return [('«', '»'), ('„', '“')]
case 'bg' | 'et':
return [('„', '“'), ('«', '»')]
case 'bs':
return [('”', '”'), ('„', '”'), ('„', '“')]
case 'cs' | 'sk' | 'sl':
return [('„', '“'), ('»', '«')]
case 'da':
return [('»', '«'), ('“', '”'), ('”', '”'), ('„', '“')]
case 'de' | 'cim':
return [('„', '“'), ('»', '«'), ('«', '»')]
case 'en':
return [('“', '”'), ('‘', '’')]
case 'eo':
return [('“', '”'), ('«', '»'), ('„', '“')]
case 'fi':
return [('”', '”'), ('»', '»')]
case 'fil' | 'ga' | 'hi' | 'ia' | 'lo' | 'mt' | 'ta' | 'th' | 'ur' | 'vi':
return [('“', '”')]
case 'fr':
return [('« ', ' »'), ('“', '”'), ('«', '»')]
case 'cy' | 'gd':
return [('‘', '’'), ('“', '”')]
case 'he':
return [('"', '"'), ('”', '„')]
case 'hr':
return [('„', '”'), ('»', '«')]
case 'hu' | 'ro':
return [('„', '”')]
case 'id':
return [('“', '”'), ('”', '”')]
case 'is' | 'ka' | 'lt' | 'mk' | 'sq' | 'wen':
return [('„', '“')]
case 'ja':
return [('「', '」'), ('﹁', '﹂')]
case 'jbo':
return [('lu ', ' li’u')]
case 'kl':
return [('"', '"'), ('»', '«')]
case 'ko':
return [('“', '”'), ('﹃', '﹄'), ('《', '》')]
case 'bo' | 'khb' | 'tdd':
return [('《', '》')]
case 'lv':
return [('“', '”'), ('„', '“')]
case 'mn':
return [('«', '»'), ('„', '“'), ('⟪', '⟫')]
case 'pl':
return [('„', '”'), ('«', '»')]
case 'pt' | 'tr':
return [('“', '”'), ('«', '»')]
case 'sr':
return [('„', '”'), ('„', '“'), ('»', '«')]
case 'sv':
return [('”', '”'), ('»', '»'), ('«', '«')]
case 'uk':
return [('«', '»'), ('„', '“'), ('„', '”')]
case 'zh':
return [('「', '」'), ('﹁', '﹂'), ('“', '”'), ('﹃', '﹄')]
case _:
return []
if level == 'secondary':
match lang:
case 'af' | 'nl':
return [('‘', '’'), ('‚', '’')]
case 'am' | 'ti':
return [('‹', '›'), ('‘', '’')]
case 'az' | 'be':
return [('„', '“')]
case 'bs':
return [('’', '’'), ('»', '«')]
case 'bg':
return [('’', '’'), ('‘', '’')]
case 'ca' | 'cy' | 'es' | 'eu' | 'gl' | 'gd' | 'uk':
return [('“', '”'), ('‘', '’')]
case 'cs' | 'sk' | 'sl':
return [('‚', '‘'), ('›', '‹')]
case 'da':
return [('›', '‹'), ('‘', '’'), ('’', '’')]
case 'de' | 'cim':
return [('‚', '‘'), ('›', '‹'), ('“', '”')]
case 'el' | 'kk' | 'km':
return [('“', '”')]
case 'en' | 'pt':
return [('‘', '’'), ('“', '”')]
case 'eo':
return [('‘', '’'), ('‹', '›'), ('‚', '‘')]
case 'fi' | 'sr':
return [('’', '’')]
case 'fil' | 'ga' | 'hi' | 'hr' | 'ia' | 'ta' | 'th' | 'ur':
return [('‘', '’')]
case 'fr':
return [('« ', ' »'), ('“', '”'), ('‹ ', ' ›'), ('‘', '’')]
case 'he':
return [('\'', '\''), ('’', ',')]
case 'hu':
return [('»', '«')]
case 'id':
return [('‘', '’'), ('’', '’')]
case 'is' | 'lt' | 'wen':
return [('‚', '‘')]
case 'it':
return [('“', '”'), ('‘', '’'), ('‹ ', ' ›')]
case 'io' | 'mt'| 'sq':
return [('‘', '’')]
case 'ja':
return [('『', '』'), ('﹃', '﹄')]
case 'jbo':
return [('lu “', '” li’u')]
case 'bo' | 'khb' | 'tdd':
return [('〈', '〉')]
case 'ko':
return [('‘', '’'), ('﹁', '﹂'), ('〈', '〉')]
case 'mk':
return [('’', '‘')]
case 'mn':
return [('„', '“'), ('⟨', '⟩')]
case 'no':
return [('‘', '’'), (',', '‘')]
case 'oc':
return [('“', '”'), ('«', '»')]
case 'pl':
return [('»', '«'), ('‘', '’')]
case 'rm' | 'ug':
return [('‹', '›')]
case 'ro' | 'vi':
return [('«', '»')]
case 'ru':
return [('„', '“'), ('‘', '’')]
case 'sv':
return [('’', '’')]
case 'tr':
return [('‘', '’'), ('‹', '›')]
case 'uz':
return [('„', '“'), ('‚', '‘')]
case 'zh':
return [('『', '』'), ('﹃', '﹄'), ('‘', '’'), ('﹁', '﹂')]
case _:
return []
def quotes_to_str_by_lang (lang):
"""Get string representation of the quotation marks of a particular language.
str `lang` - ISO code of the language.
return str - string representation of the quotation marks.
"""
quotes_list = []
for q in get_quotes(lang):
for c in q:
quotes_list.append(c)
return ''.join(sorted(quotes_list))
def brackets_to_str (brackets):
"""Get string representation of brackets returned by the `get_quotes` function.
list `brackets` - list of tuples, each tuple is of length 2, containing opening and
closing quotation marks.
return str - string representation of brackets.
"""
brackets_list = []
for b in brackets:
for c in b:
brackets_list.append(c)
return ''.join(sorted(brackets_list))