Left: | ||
Right: |
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-2015 Eyeo GmbH | 4 # Copyright (C) 2006-2015 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 cms.converters import converters, TemplateConverter | 18 from cms.converters import converters, TemplateConverter |
19 | 19 |
20 def get_page_params(source, locale, page, format=None, site_url_override=None, | 20 def get_page_params(source, locale, page, format=None, site_url_override=None, |
21 record_default_strings=None): | 21 localized_string_callback=None): |
Wladimir Palant
2015/07/08 23:11:09
Nit: This should be record_default_string as the c
kzar
2015/07/11 19:21:18
Done.
| |
22 # Guess page format if omitted, but default to Markdown for friendlier excepti ons | 22 # Guess page format if omitted, but default to Markdown for friendlier excepti ons |
23 if format is None: | 23 if format is None: |
24 for format in converters.iterkeys(): | 24 for format in converters.iterkeys(): |
25 if source.has_page(page, format): | 25 if source.has_page(page, format): |
26 break | 26 break |
27 else: | 27 else: |
28 format = "md" | 28 format = "md" |
29 | 29 |
30 params = { | 30 params = { |
31 "source": source, | 31 "source": source, |
32 "template": "default", | 32 "template": "default", |
33 "locale": locale, | 33 "locale": locale, |
34 "page": page, | 34 "page": page, |
35 "pagedata": source.read_page(page, format), | 35 "pagedata": source.read_page(page, format), |
36 "config": source.read_config(), | 36 "config": source.read_config(), |
37 "record_default_strings": record_default_strings, | 37 "localized_string_callback": localized_string_callback, |
38 } | 38 } |
39 | 39 |
40 localefile = page | 40 localefile = page |
41 if params["config"].has_option("locale_overrides", page): | 41 if params["config"].has_option("locale_overrides", page): |
42 localefile = params["config"].get("locale_overrides", page) | 42 localefile = params["config"].get("locale_overrides", page) |
43 params["localedata"] = source.read_locale(params["locale"], localefile) | 43 params["localedata"] = source.read_locale(params["locale"], localefile) |
44 | 44 |
45 if params["config"].has_option("general", "siteurl"): | 45 if params["config"].has_option("general", "siteurl"): |
46 if site_url_override: | 46 if site_url_override: |
47 params["site_url"] = site_url_override | 47 params["site_url"] = site_url_override |
(...skipping 25 matching lines...) Expand all Loading... | |
73 params["head"], params["body"] = converter() | 73 params["head"], params["body"] = converter() |
74 if converter.total_translations > 0: | 74 if converter.total_translations > 0: |
75 params["translation_ratio"] = (1 - | 75 params["translation_ratio"] = (1 - |
76 float(converter.missing_translations) / converter.total_translations) | 76 float(converter.missing_translations) / converter.total_translations) |
77 else: | 77 else: |
78 params["translation_ratio"] = 1 | 78 params["translation_ratio"] = 1 |
79 | 79 |
80 return params | 80 return params |
81 | 81 |
82 def process_page(source, locale, page, format=None, site_url_override=None, | 82 def process_page(source, locale, page, format=None, site_url_override=None, |
83 record_default_strings=None): | 83 localized_string_callback=None): |
84 return TemplateConverter( | 84 return TemplateConverter( |
85 get_page_params(source, locale, page, format, | 85 get_page_params(source, locale, page, format, |
86 site_url_override, record_default_strings), | 86 site_url_override, localized_string_callback), |
87 key="templatedata" | 87 key="templatedata" |
88 )() | 88 )() |
LEFT | RIGHT |