Пример #1
0
 def test_add_translations(self):
     ts1 = TranslationString('first', domain = 'hello')
     ts2 = TranslationString('second', domain = 'world')
     obj = self._cut()
     obj.add_translations(first = ts1, second = ts2)
     self.assertIn('first', obj.translations)
     self.assertIn('second', obj.translations)
Пример #2
0
 def test_get_translations(self):
     ts1 = TranslationString('first', domain = 'hello')
     ts2 = TranslationString('second', domain = 'world')
     obj = self._cut()
     obj.add_translations(first = ts1, second = ts2)
     res = obj.get_translations()
     self.assertIn('first', res)
     self.assertIn('second', res)
     self.assertEqual(res['first'], ts1)
Пример #3
0
 def test_subject_translated(self):
     self.config.add_translation_dirs('voteit.core:locale/')
     self.config.registry.settings['default_locale_name'] = 'sv'
     html = "<p>Hello!</p>"
     subject = TranslationString(u'Reply', domain='voteit.core')
     msg = self._fut(subject=subject, recipients='*****@*****.**', html=html)
     self.assertEqual(msg.subject, u'Svara')
Пример #4
0
 def test_default_translate(self):
     from pyramid.i18n import TranslationString
     lookup = DummyLookup()
     lookup.translate = None
     path = self._get_template_path('minimal.genshi')
     renderer = self.make_one(path, lookup)
     ts = renderer.translate('hello')
     self.assertIsInstance(ts, TranslationString)
     self.assertEqual(ts, TranslationString('hello'))
Пример #5
0
 def test_translate(self):
     context = testing.DummyResource()
     request = testing.DummyRequest()
     from pyramid.i18n import TranslationString
     dummy_ts = TranslationString("Hello")
     obj = self._cut(context, request)
     res = obj.translate(dummy_ts)
     self.assertIsInstance(res, unicode)
     self.assertNotIsInstance(res, TranslationString)
Пример #6
0
    def auto_translate(*args, **kwargs):
        # lets pass default domain, so we don't have to determine it with
        # each _() function in apps.
        if len(args) <= 1 and 'domain' not in kwargs:
            kwargs['domain'] = request.registry['config'].localize.domain

        # unlike in examples we use TranslationString, to make sure we always
        # use appropriate domain
        return request.localizer.translate(TranslationString(*args, **kwargs))
Пример #7
0
 def __init__(self, data_param):
     """Construct error message with the data param information."""
     message = (TranslationString(
         "Required LTI data param for content item selection missing: ") +
                data_param)
     super(MissingLTIContentItemParamError, self).__init__(message)
Пример #8
0
 def test_add_translations_no_domain(self):
     ts = TranslationString('no_domain_added')
     obj = self._cut()
     self.assertRaises(ValueError, obj.add_translations, bad = ts)
Пример #9
0
 def test_add_translations_bad_js_id(self):
     ts = TranslationString('hello"', domain = 'hello')
     obj = self._cut()
     kws = {'$very!bad': ts}
     self.assertRaises(ValueError, obj.add_translations, **kws)
Пример #10
0
 def _makeOne(self, *arg, **kw):
     from pyramid.i18n import TranslationString
     return TranslationString(*arg, **kw)
Пример #11
0
 def translate(*args, **kwargs):
     if 'domain' not in kwargs:
         kwargs['domain'] = 'message'
     ts = TranslationString(*args, **kwargs)
     return localizer.translate(ts)
Пример #12
0
def get2(request):
    return request.errors.add('body', 'field',
                              TranslationString('Description'))
Пример #13
0
 def localize(message, **kwargs):
     ts = TranslationString(message, **kwargs)
     return ts.interpolate()
Пример #14
0
 def __init__(self, data_param):
     """Construct error message with the data param information."""
     message = (
         TranslationString("Required data param for LTI launch missing: ") +
         data_param)
     super(MissingLTILaunchParamError, self).__init__(message)
Пример #15
0
 def auto_translate(*args, **kwargs):
     if 'domain' not in kwargs:
         kwargs['domain'] = mr
     return get_localizer(request).translate(
         TranslationString(*args, **kwargs))
Пример #16
0
 def ugettext(self, message, domain=None):
     if domain is None:
         domain = self.default_domain
     tmsg = self.translate(TranslationString(message, domain=domain))
     return tmsg
Пример #17
0
 def translate(self, *args, **kwargs):
     kwargs.setdefault('domain', self.default_domain)
     ts = TranslationString(*args, **kwargs)
     if self.lookup.translate is not None:
         return self.lookup.translate(ts)
     return ts