Mercurial > genshi > mirror
comparison genshi/filters/tests/i18n.py @ 784:ea46fb523485 experimental-match-fastpaths
update to 0.5.x branch, up through r907
don't know how this fits in with SoC work, but I wanted to do due diligence and keep this branch working in case it someday gets considered for trunk
author | aflett |
---|---|
date | Mon, 21 Jul 2008 23:17:52 +0000 |
parents | 919809e55d16 |
children | 36fb0a57fe74 |
comparison
equal
deleted
inserted
replaced
724:919809e55d16 | 784:ea46fb523485 |
---|---|
9 # | 9 # |
10 # This software consists of voluntary contributions made by many | 10 # This software consists of voluntary contributions made by many |
11 # individuals. For the exact contribution history, see the revision | 11 # individuals. For the exact contribution history, see the revision |
12 # history and logs, available at http://genshi.edgewall.org/log/. | 12 # history and logs, available at http://genshi.edgewall.org/log/. |
13 | 13 |
14 from datetime import datetime | |
14 import doctest | 15 import doctest |
15 from StringIO import StringIO | 16 from StringIO import StringIO |
16 import unittest | 17 import unittest |
17 | 18 |
18 from genshi.core import Attrs | 19 from genshi.core import Attrs |
259 gettext = lambda s: u"[1:] Einträge pro Seite, beginnend auf Seite [2:]." | 260 gettext = lambda s: u"[1:] Einträge pro Seite, beginnend auf Seite [2:]." |
260 tmpl.filters.insert(0, Translator(gettext)) | 261 tmpl.filters.insert(0, Translator(gettext)) |
261 self.assertEqual("""<html> | 262 self.assertEqual("""<html> |
262 <p><input type="text" name="num"/> Eintr\xc3\xa4ge pro Seite, beginnend auf Seite <input type="text" name="num"/>.</p> | 263 <p><input type="text" name="num"/> Eintr\xc3\xa4ge pro Seite, beginnend auf Seite <input type="text" name="num"/>.</p> |
263 </html>""", tmpl.generate().render()) | 264 </html>""", tmpl.generate().render()) |
265 | |
266 def test_extract_i18n_msg_with_param(self): | |
267 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
268 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
269 <p i18n:msg="name"> | |
270 Hello, ${user.name}! | |
271 </p> | |
272 </html>""") | |
273 translator = Translator() | |
274 messages = list(translator.extract(tmpl.stream)) | |
275 self.assertEqual(1, len(messages)) | |
276 self.assertEqual('Hello, %(name)s!', messages[0][2]) | |
277 | |
278 def test_translate_i18n_msg_with_param(self): | |
279 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
280 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
281 <p i18n:msg="name"> | |
282 Hello, ${user.name}! | |
283 </p> | |
284 </html>""") | |
285 gettext = lambda s: u"Hallo, %(name)s!" | |
286 tmpl.filters.insert(0, Translator(gettext)) | |
287 self.assertEqual("""<html> | |
288 <p>Hallo, Jim!</p> | |
289 </html>""", tmpl.generate(user=dict(name='Jim')).render()) | |
290 | |
291 def test_translate_i18n_msg_with_param_reordered(self): | |
292 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
293 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
294 <p i18n:msg="name"> | |
295 Hello, ${user.name}! | |
296 </p> | |
297 </html>""") | |
298 gettext = lambda s: u"%(name)s, sei gegrüßt!" | |
299 tmpl.filters.insert(0, Translator(gettext)) | |
300 self.assertEqual("""<html> | |
301 <p>Jim, sei gegrüßt!</p> | |
302 </html>""", tmpl.generate(user=dict(name='Jim')).render()) | |
303 | |
304 def test_extract_i18n_msg_with_two_params(self): | |
305 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
306 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
307 <p i18n:msg="name, time"> | |
308 Posted by ${post.author} at ${entry.time.strftime('%H:%m')} | |
309 </p> | |
310 </html>""") | |
311 translator = Translator() | |
312 messages = list(translator.extract(tmpl.stream)) | |
313 self.assertEqual(1, len(messages)) | |
314 self.assertEqual('Posted by %(name)s at %(time)s', messages[0][2]) | |
315 | |
316 def test_translate_i18n_msg_with_two_params(self): | |
317 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
318 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
319 <p i18n:msg="name, time"> | |
320 Written by ${entry.author} at ${entry.time.strftime('%H:%M')} | |
321 </p> | |
322 </html>""") | |
323 gettext = lambda s: u"%(name)s schrieb dies um %(time)s" | |
324 tmpl.filters.insert(0, Translator(gettext)) | |
325 entry = { | |
326 'author': 'Jim', | |
327 'time': datetime(2008, 4, 1, 14, 30) | |
328 } | |
329 self.assertEqual("""<html> | |
330 <p>Jim schrieb dies um 14:30</p> | |
331 </html>""", tmpl.generate(entry=entry).render()) | |
264 | 332 |
265 def test_extract_i18n_msg_with_directive(self): | 333 def test_extract_i18n_msg_with_directive(self): |
266 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | 334 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
267 xmlns:i18n="http://genshi.edgewall.org/i18n"> | 335 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
268 <p i18n:msg=""> | 336 <p i18n:msg=""> |