Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: cms/sources.py

Issue 29659605: Issue 6231 - Add tests for translation string substitution (Closed)
Left Patch Set: Created Jan. 8, 2018, 5:31 p.m.
Right Patch Set: Add tests for partial translation and for get_string Created Jan. 19, 2018, 3:26 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | tests/expected_output/de/translate » ('j') | tests/test_page_outputs.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 def has_static(self, filename): 140 def has_static(self, filename):
141 return self.has_file(self.static_filename(filename)) 141 return self.has_file(self.static_filename(filename))
142 142
143 def read_static(self, filename): 143 def read_static(self, filename):
144 return self.read_file(self.static_filename(filename), binary=True)[0] 144 return self.read_file(self.static_filename(filename), binary=True)[0]
145 145
146 # 146 #
147 # Locale helpers 147 # Locale helpers
148 # 148 #
149 149
150 @classmethod 150 def locale_filename(self, locale, page):
151 def locale_filename(cls, locale, page): 151 config = self.read_config()
152 return cls.localizable_file_filename(locale, page + '.json') 152 try:
153 page = config.get('locale_overrides', page)
154 except ConfigParser.Error:
155 pass
156 return self.localizable_file_filename(locale, page + '.json')
153 157
154 def list_locales(self): 158 def list_locales(self):
155 result = set() 159 result = set()
156 for filename in self.list_files('locales'): 160 for filename in self.list_files('locales'):
157 if '/' in filename: 161 if '/' in filename:
158 locale, path = filename.split('/', 1) 162 locale, path = filename.split('/', 1)
159 result.add(locale) 163 result.add(locale)
160 return result 164 return result
161 165
162 def has_locale(self, locale, page): 166 def has_locale(self, locale, page):
163 config = self.read_config()
164 try:
165 page = config.get('locale_overrides', page)
166 except ConfigParser.Error:
167 pass
168 return self.has_file(self.locale_filename(locale, page)) 167 return self.has_file(self.locale_filename(locale, page))
169 168
170 def read_locale(self, locale, page): 169 def read_locale(self, locale, page):
171 default_locale = self.read_config().get('general', 'defaultlocale') 170 default_locale = self.read_config().get('general', 'defaultlocale')
172 result = collections.OrderedDict() 171 result = collections.OrderedDict()
173 if locale != default_locale: 172 if locale != default_locale:
174 result.update(self.read_locale(default_locale, page)) 173 result.update(self.read_locale(default_locale, page))
175 174
176 if self.has_locale(locale, page): 175 if self.has_locale(locale, page):
177 filename = self.locale_filename(locale, page) 176 filename = self.locale_filename(locale, page)
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 'resolve_link', 450 'resolve_link',
452 'read_config', 451 'read_config',
453 'read_template', 452 'read_template',
454 'read_locale', 453 'read_locale',
455 'read_include', 454 'read_include',
456 'exec_file', 455 'exec_file',
457 ]: 456 ]:
458 setattr(source, fname, _memoize(getattr(source, fname))) 457 setattr(source, fname, _memoize(getattr(source, fname)))
459 458
460 return source 459 return source
LEFTRIGHT

Powered by Google App Engine
This is Rietveld