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)
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)
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')
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'))
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)
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))
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)
def test_add_translations_no_domain(self): ts = TranslationString('no_domain_added') obj = self._cut() self.assertRaises(ValueError, obj.add_translations, bad = ts)
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)
def _makeOne(self, *arg, **kw): from pyramid.i18n import TranslationString return TranslationString(*arg, **kw)
def translate(*args, **kwargs): if 'domain' not in kwargs: kwargs['domain'] = 'message' ts = TranslationString(*args, **kwargs) return localizer.translate(ts)
def get2(request): return request.errors.add('body', 'field', TranslationString('Description'))
def localize(message, **kwargs): ts = TranslationString(message, **kwargs) return ts.interpolate()
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)
def auto_translate(*args, **kwargs): if 'domain' not in kwargs: kwargs['domain'] = mr return get_localizer(request).translate( TranslationString(*args, **kwargs))
def ugettext(self, message, domain=None): if domain is None: domain = self.default_domain tmsg = self.translate(TranslationString(message, domain=domain)) return tmsg
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