LEFT | RIGHT |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
4 # Copyright (C) 2006-2013 Eyeo GmbH | 4 # Copyright (C) 2006-2013 Eyeo GmbH |
5 # | 5 # |
6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
9 # | 9 # |
10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
14 # | 14 # |
15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
18 from .converters import converters, TemplateConverter | 18 from .converters import converters, TemplateConverter |
19 | 19 |
20 def process_page(source, locale, page, format): | 20 def process_page(source, locale, page, format): |
21 params = { | 21 params = { |
22 "source": source, | 22 "source": source, |
23 "template": "default", | 23 "template": "default", |
24 "locale": locale, | 24 "locale": locale, |
25 "title": "title", | 25 "title": "title", |
26 "page": page, | 26 "page": page, |
27 "pagedata": source.read_page(page, format), | 27 "pagedata": source.read_page(page, format), |
28 "toc": True, | |
29 "config": source.read_config(), | 28 "config": source.read_config(), |
30 } | 29 } |
| 30 |
| 31 localefile = page |
| 32 if params["config"].has_option("locale_overrides", page): |
| 33 localefile = params["config"].get("locale_overrides", page) |
| 34 params["localedata"] = source.read_locale(params["locale"], localefile) |
31 | 35 |
32 try: | 36 try: |
33 converter = converters[format](params) | 37 converter = converters[format](params) |
34 except KeyError: | 38 except KeyError: |
35 raise Exception("Page %s uses unknown format %s" % (page, format)) | 39 raise Exception("Page %s uses unknown format %s" % (page, format)) |
36 | 40 |
37 # Note: The converter might change some parameters so we can only read in | 41 # Note: The converter might change some parameters so we can only read in |
38 # template and locale data here. | 42 # template data here. |
39 params["templatedata"] = source.read_template(params["template"]) | 43 params["templatedata"] = source.read_template(params["template"]) |
40 params["localedata"] = source.read_locale(params["locale"], params["page"]) | |
41 template_converter = TemplateConverter(params, key="templatedata") | 44 template_converter = TemplateConverter(params, key="templatedata") |
42 | 45 |
43 params["available_locales"] = sorted( | 46 params["available_locales"] = sorted( |
44 filter( | 47 filter( |
45 lambda locale: source.has_locale(locale, params["page"]), | 48 lambda locale: source.has_locale(locale, localefile), |
46 source.list_locales() | 49 source.list_locales() |
47 ) | 50 ) |
48 ) | 51 ) |
49 | 52 |
50 params["head"], params["body"] = converter() | 53 params["head"], params["body"] = converter() |
51 return template_converter() | 54 return template_converter() |
LEFT | RIGHT |