/
strings.py
299 lines (256 loc) · 11.9 KB
/
strings.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# -*- coding: utf-8 ; test-case-name: bridgedb.test.test_strings ; -*-
#
# This file is part of BridgeDB, a Tor bridge distribution system.
#
# :authors: Isis Lovecruft 0xA3ADB67A2CDB8B35 <isis@torproject.org>
# :copyright: (c) 2007-2015, The Tor Project, Inc.
# (c) 2013-2015, Isis Lovecruft
# (c) 2007-2015, all entities within the AUTHORS file
# :license: 3-clause BSD, see included LICENSE for information
from __future__ import unicode_literals
# This won't work on Python2.6, however
# 1) We don't use Python2.6, and
# 2) We don't care about supporting Python2.6, because Python 2.6 (and,
# honestly, all of Python2) should die.
from collections import OrderedDict
def _(text):
"""This is necessary because strings are translated when they're imported.
Otherwise this would make it impossible to switch languages more than
once.
:returns: The **text**.
"""
return text
# TRANSLATORS: Please do not translate the word "TYPE".
EMAIL_MISC_TEXT = {
0: _("""\
[This is an automated message; please do not reply.]"""),
1: _("""\
Here are your bridges:"""),
2: _("""\
You have exceeded the rate limit. Please slow down! The minimum time between
emails is %s hours. All further emails during this time period will be ignored."""),
3: _("""\
COMMANDs: (combine COMMANDs to specify multiple options simultaneously)"""),
# TRANSLATORS: Please DO NOT translate the word "BridgeDB".
4: _("Welcome to BridgeDB!"),
# TRANSLATORS: Please DO NOT translate the words "transport" or "TYPE".
5: _("Currently supported transport TYPEs:"),
6: _("Hey, %s!"),
7: _("Hello, friend!"),
8: _("Public Keys"),
# TRANSLATORS: This string will end up saying something like:
# "This email was generated with rainbows, unicorns, and sparkles
# for alice@example.com on Friday, 09 May, 2014 at 18:59:39."
9: _("""\
This email was generated with rainbows, unicorns, and sparkles
for %s on %s at %s."""),
}
WELCOME = {
# TRANSLATORS: Please DO NOT translate "BridgeDB".
# TRANSLATORS: Please DO NOT translate "Pluggable Transports".
# TRANSLATORS: Please DO NOT translate "Tor".
# TRANSLATORS: Please DO NOT translate "Tor Network".
0: _("""\
BridgeDB can provide bridges with several %stypes of Pluggable Transports%s,
which can help obfuscate your connections to the Tor Network, making it more
difficult for anyone watching your internet traffic to determine that you are
using Tor.\n\n"""),
# TRANSLATORS: Please DO NOT translate "Pluggable Transports".
1: _("""\
Some bridges with IPv6 addresses are also available, though some Pluggable
Transports aren't IPv6 compatible.\n\n"""),
# TRANSLATORS: Please DO NOT translate "BridgeDB".
# TRANSLATORS: The phrase "plain-ol'-vanilla" means "plain, boring,
# regular, or unexciting". Like vanilla ice cream. It refers to bridges
# which do not have Pluggable Transports, and only speak the regular,
# boring Tor protocol. Translate it as you see fit. Have fun with it.
2: _("""\
Additionally, BridgeDB has plenty of plain-ol'-vanilla bridges %s without any
Pluggable Transports %s which maybe doesn't sound as cool, but they can still
help to circumvent internet censorship in many cases.\n\n"""),
}
"""These strings should go on the first "Welcome" email sent by the
:mod:`~bridgedb.EmailServer`, as well as on the ``index.html`` template used
by the :mod:`~bridgedb.HTTPServer`. They are used as an introduction to
explain what Tor bridges are, what bridges do, and why someone might want to
use bridges.
"""
FAQ = {
0: _("What are bridges?"),
1: _("""\
%s Bridges %s are Tor relays that help you circumvent censorship."""),
}
OTHER_DISTRIBUTORS = {
0: _("I need an alternative way of getting bridges!"),
1: _("""\
Another way to get bridges is to send an email to %s. Please note that you must
send the email using an address from one of the following email providers:
%s, %s or %s."""),
}
HELP = {
0: _("My bridges don't work! I need help!"),
# TRANSLATORS: Please DO NOT translate "Tor".
1: _("""If your Tor doesn't work, you should email %s."""),
# TRANSLATORS: Please DO NOT translate "Pluggable Transports".
# TRANSLATORS: Please DO NOT translate "Tor Browser".
# TRANSLATORS: Please DO NOT translate "Tor".
2: _("""\
Try including as much info about your case as you can, including the list of
bridges and Pluggable Transports you tried to use, your Tor Browser version,
and any messages which Tor gave out, etc."""),
}
BRIDGES = {
0: _("Here are your bridge lines:"),
1: _("Get Bridges!"),
}
OPTIONS = {
0: _("Please select options for bridge type:"),
1: _("Do you need IPv6 addresses?"),
2: _("Do you need a %s?"),
}
CAPTCHA = {
0: _('Your browser is not displaying images properly.'),
1: _('Enter the characters from the image above...'),
}
HOWTO_TBB = {
0: _("""How to start using your bridges"""),
# TRANSLATORS: Please DO NOT translate "Tor Browser".
1: _("""\
To enter bridges into Tor Browser, first go to the %s Tor Browser download
page %s and then follow the instructions there for downloading and starting
Tor Browser."""),
# TRANSLATORS: Please DO NOT translate "Tor".
2: _("""\
When the 'Tor Network Settings' dialogue pops up, click 'Configure' and follow
the wizard until it asks:"""),
# TRANSLATORS: Please DO NOT translate "Tor".
3: _("""\
Does your Internet Service Provider (ISP) block or otherwise censor connections
to the Tor network?"""),
# TRANSLATORS: Please DO NOT translate "Tor".
4: _("""\
Select 'Yes' and then click 'Next'. To configure your new bridges, copy and
paste the bridge lines into the text input box. Finally, click 'Connect', and
you should be good to go! If you experience trouble, try clicking the 'Help'
button in the 'Tor Network Settings' wizard for further assistance."""),
}
EMAIL_COMMANDS = {
"get help": _("Displays this message."),
# TRANSLATORS: Please try to make it clear that "vanilla" here refers to the
# same non-Pluggable Transport bridges described above as being
# "plain-ol'-vanilla" bridges.
"get bridges": _("Request vanilla bridges."),
"get ipv6": _("Request IPv6 bridges."),
# TRANSLATORS: Please DO NOT translate the word the word "TYPE".
"get transport [TYPE]": _("Request a Pluggable Transport by TYPE."),
# TRANSLATORS: Please DO NOT translate "BridgeDB".
# TRANSLATORS: Please DO NOT translate "GnuPG".
"get key": _("Get a copy of BridgeDB's public GnuPG key."),
#"subscribe": _("Subscribe to receive new bridges once per week"),
#"unsubscribe": _("Cancel a subscription to new bridges"),
}
#-----------------------------------------------------------------------------
# All of the following containers are untranslated!
#-----------------------------------------------------------------------------
#: SUPPORTED TRANSPORTS is dictionary mapping all Pluggable Transports
#: methodname to whether or not we actively distribute them. The ones which we
#: distribute SHOULD have the following properties:
#:
#: 1. The PT is in a widely accepted, usable state for most Tor users.
#: 2. The PT is currently publicly deployed *en masse*".
#: 3. The PT is included within the transports which Tor Browser offers in
#: the stable releases.
#:
#: These will be sorted by methodname in alphabetical order.
#:
#: ***Don't change this setting here; change it in :file:`bridgedb.conf`.***
SUPPORTED_TRANSPORTS = {}
#: DEFAULT_TRANSPORT is a string. It should be the PT methodname of the
#: transport which is selected by default (e.g. in the webserver dropdown
#: menu).
#:
#: ***Don't change this setting here; change it in :file:`bridgedb.conf`.***
DEFAULT_TRANSPORT = ''
def _getSupportedTransports():
"""Get the list of currently supported transports.
:rtype: list
:returns: A list of strings, one for each supported Pluggable Transport
methodname, sorted in alphabetical order.
"""
supported = [name.lower() for name,w00t in SUPPORTED_TRANSPORTS.items() if w00t]
supported.sort()
return supported
def _setDefaultTransport(transport):
global DEFAULT_TRANSPORT
DEFAULT_TRANSPORT = transport
def _getDefaultTransport():
return DEFAULT_TRANSPORT
def _setSupportedTransports(transports):
"""Set the list of currently supported transports.
.. note: You shouldn't need to touch this. This is used by the config file
parser. You should change the SUPPORTED_TRANSPORTS dictionary in
:file:`bridgedb.conf`.
:param dict transports: A mapping of Pluggable Transport methodnames
(strings) to booleans. If the boolean is ``True``, then the Pluggable
Transport is one which we will (more easily) distribute to clients.
If ``False``, then we (sort of) don't distribute it.
"""
global SUPPORTED_TRANSPORTS
SUPPORTED_TRANSPORTS = transports
def _getSupportedAndDefaultTransports():
"""Get a dictionary of currently supported transports, along with a boolean
marking which transport is the default.
It is returned as a :class:`collections.OrderedDict`, because if it is a
regular dict, then the dropdown menu would populated in random order each
time the page is rendered. It is sorted in alphabetical order.
:rtype: :class:`collections.OrderedDict`
:returns: An :class:`~collections.OrderedDict` of the Pluggable Transport
methodnames from :data:`SUPPORTED_TRANSPORTS` whose value in
``SUPPORTED_TRANSPORTS`` is ``True``. If :data:`DEFAULT_TRANSPORT` is
set, then the PT methodname in the ``DEFAULT_TRANSPORT`` setting is
added to the :class:`~collections.OrderedDict`, with the value
``True``. Every other transport in the returned ``OrderedDict`` has
its value set to ``False``, so that only the one which should be the
default PT is ``True``.
"""
supported = _getSupportedTransports()
transports = OrderedDict(zip(supported, [False for _ in range(len(supported))]))
if DEFAULT_TRANSPORT:
transports[DEFAULT_TRANSPORT] = True
return transports
EMAIL_SPRINTF = {
# Goes into the "%s types of Pluggable Transports %s" part of ``WELCOME[0]``
"WELCOME0": ("", "[0]"),
# Goes into the "%s without Pluggable Transport %s" part of ``WELCOME[2]``
"WELCOME2": ("-", "-"),
# For the "%s Tor Browser download page %s" part of ``HOWTO_TBB[1]``
"HOWTO_TBB1": ("", "[0]"),
# For the "you should email %s" in ``HELP[0]``
"HELP0": ("help@rt.torproject.org"),
}
"""``EMAIL_SPRINTF`` is a dictionary that maps translated strings which
contain format specifiers (i.e. ``%s``) to what those format specifiers should
be replaced with in a given template system.
For example, a string which needs a pair of HTML ``("<a href=''">, "</a>")``
tags (for the templates used by :mod:`bridgedb.HTTPServer`) would need some
alternative replacements for the :mod:`EmailServer`, because the latter uses
templates with a ``text/plain`` mimetype instead of HTML. For the
``EmailServer``, the format strings specifiers are replaced with an empty
string where the opening ``<a>`` tags would go, and a numbered Markdown link
specifier where the closing ``</a>`` tags would go.
The keys in this dictionary are the Python variable names of the corresponding
strings which are being formatted, i.e. ``WELCOME0`` would be the string
replacements for ``strings.WELCOME.get(0)``.
For example, the ``0`` string in :data:`WELCOME` above has the substring::
"%s without Pluggable Transport %s"
and so to replace the two ``%s`` format specifiers, you would use this mapping
like so::
>>> from bridgedb import strings
>>> welcome = strings.WELCOME[0] % strings.EMAIL_SPRINTF["WELCOME0"]
>>> print welcome.split('\n')[0]
BridgeDB can provide bridges with several types of Pluggable Transports[0],
"""
EMAIL_REFERENCE_LINKS = {
"WELCOME0": "[0]: https://www.torproject.org/docs/pluggable-transports.html",
"HOWTO_TBB1": "[0]: https://www.torproject.org/projects/torbrowser.html",
}