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
|
self.language_file = None
self.http_accept_language = request.env.http_accept_language
self.requested_languages = self.force(self.http_accept_language)
self.lazy = True
self.otherTs = {}
def get_possible_languages(self):
possible_languages = self.current_languages
file_ending = re.compile("\.py$")
for langfile in os.listdir(os.path.join(self.folder,'languages')):
if file_ending.search(langfile):
possible_languages.append(file_ending.sub('',langfile))
return possible_languages
def set_current_languages(self, *languages):
if len(languages) == 1 and isinstance(languages[0], (tuple, list)):
languages = languages[0]
self.current_languages = languages
self.force(self.http_accept_language)
def force(self, *languages):
if not languages or languages[0] == None:
languages = []
if len(languages) == 1 and isinstance(languages[0], (str, unicode)):
languages = languages[0]
if languages:
if isinstance(languages, (str, unicode)):
accept_languages = languages.split(';')
languages = []
|
|
|
|
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
|
self.language_file = None
self.http_accept_language = request.env.http_accept_language
self.requested_languages = self.force(self.http_accept_language)
self.lazy = True
self.otherTs = {}
def get_possible_languages(self):
possible_languages = [lang for lang in self.current_languages]
file_ending = re.compile("\.py$")
for langfile in os.listdir(os.path.join(self.folder,'languages')):
if file_ending.search(langfile):
possible_languages.append(file_ending.sub('',langfile))
return possible_languages
def set_current_languages(self, *languages):
if len(languages) == 1 and isinstance(languages[0], (tuple, list)):
languages = languages[0]
self.current_languages = languages
self.force(self.http_accept_language)
def force(self, *languages):
if not languages or languages[0] is None:
languages = []
if len(languages) == 1 and isinstance(languages[0], (str, unicode)):
languages = languages[0]
if languages:
if isinstance(languages, (str, unicode)):
accept_languages = languages.split(';')
languages = []
|
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
self.language_file = filename
self.t = read_dict(filename)
return languages
self.language_file = None
self.t = {} # ## no language by default
return languages
def __call__(self, message, symbols={},language=None):
if not language:
if self.lazy:
return lazyT(message, symbols, self)
else:
return self.translate(message, symbols)
else:
try:
|
|
|
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
self.language_file = filename
self.t = read_dict(filename)
return languages
self.language_file = None
self.t = {} # ## no language by default
return languages
def __call__(self, message, symbols={}, language=None):
if not language:
if self.lazy:
return lazyT(message, symbols, self)
else:
return self.translate(message, symbols)
else:
try:
|
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
T(' hello world ') -> ' hello world '
T(' hello world ## token') -> 'hello world'
T('hello ## world ## token') -> 'hello ## world'
the ## notation is ignored in multiline strings and strings that
start with ##. this is to allow markmin syntax to be translated
"""
if not message.startswith('#') and not '\n' in message:
tokens = message.rsplit('##', 1)
else:
# this allows markmin syntax in translations
tokens = [message]
if len(tokens) == 2:
tokens[0] = tokens[0].strip()
message = tokens[0] + '##' + tokens[1].strip()
mt = self.t.get(message, None)
if mt == None:
self.t[message] = mt = tokens[0]
if self.language_file and not is_gae:
write_dict(self.language_file, self.t)
if symbols or symbols == 0:
return mt % symbols
return mt
|
>
>
>
|
|
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
|
T(' hello world ') -> ' hello world '
T(' hello world ## token') -> 'hello world'
T('hello ## world ## token') -> 'hello ## world'
the ## notation is ignored in multiline strings and strings that
start with ##. this is to allow markmin syntax to be translated
"""
#for some reason languages.py gets executed before gaehandler.py
# is able to set web2py_runtime_gae, so re-check here
is_gae = settings.global_settings.web2py_runtime_gae
if not message.startswith('#') and not '\n' in message:
tokens = message.rsplit('##', 1)
else:
# this allows markmin syntax in translations
tokens = [message]
if len(tokens) == 2:
tokens[0] = tokens[0].strip()
message = tokens[0] + '##' + tokens[1].strip()
mt = self.t.get(message, None)
if mt is None:
self.t[message] = mt = tokens[0]
if self.language_file and not is_gae:
write_dict(self.language_file, self.t)
if symbols or symbols == 0:
return mt % symbols
return mt
|
340
341
342
343
344
345
346
347
348
|
for language in listdir(path, '^\w+(\-\w+)?\.py$'):
findT(application_path, language[:-3])
if __name__ == '__main__':
import doctest
doctest.testmod()
|
>
>
|
343
344
345
346
347
348
349
350
351
352
353
|
for language in listdir(path, '^\w+(\-\w+)?\.py$'):
findT(application_path, language[:-3])
if __name__ == '__main__':
import doctest
doctest.testmod()
|