Show More
@@ -1,50 +1,54 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2016 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | |
|
22 | 22 | import pylons |
|
23 | 23 | from pyramid.i18n import get_localizer, TranslationStringFactory |
|
24 | from pyramid.threadlocal import get_current_request | |
|
24 | 25 | |
|
25 | 26 | tsf = TranslationStringFactory('rc_root') |
|
26 | 27 | |
|
27 | 28 | |
|
28 | 29 | def add_renderer_globals(event): |
|
29 | 30 | # Put pylons stuff into the context. This will be removed as soon as |
|
30 | 31 | # migration to pyramid is finished. |
|
31 | 32 | conf = pylons.config._current_obj() |
|
32 | 33 | event['h'] = conf.get('pylons.h') |
|
33 | 34 | event['c'] = pylons.tmpl_context |
|
34 | 35 | event['url'] = pylons.url |
|
35 | 36 | |
|
37 | # TODO: When executed in pyramid view context the request is not available | |
|
38 | # in the event. Find a better solution to get the request. | |
|
39 | request = event['request'] or get_current_request() | |
|
40 | ||
|
36 | 41 | # Add Pyramid translation as '_' to context |
|
37 | request = event['request'] | |
|
38 | 42 | event['_'] = request.translate |
|
39 | 43 | event['localizer'] = request.localizer |
|
40 | 44 | |
|
41 | 45 | |
|
42 | 46 | def add_localizer(event): |
|
43 | 47 | request = event.request |
|
44 | 48 | localizer = get_localizer(request) |
|
45 | 49 | |
|
46 | 50 | def auto_translate(*args, **kwargs): |
|
47 | 51 | return localizer.translate(tsf(*args, **kwargs)) |
|
48 | 52 | |
|
49 | 53 | request.localizer = localizer |
|
50 | 54 | request.translate = auto_translate |
General Comments 0
You need to be logged in to leave comments.
Login now