def test_i18n_intword(self):
     test_list = ('100', '1000000', '1200000', '1290000', '1000000000',
                  '2000000000', '6000000000000')
     result_list = ('100', '1,0 Million', '1,2 Millionen', '1,3 Millionen',
                    '1,0 Milliarde', '2,0 Milliarden', '6,0 Billionen')
     with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True):
         with translation.override('de'):
             self.humanize_tester(test_list, result_list, 'intword')
 def test_i18n_intcomma(self):
     test_list = (100, 1000, 10123, 10311, 1000000, 1234567.25, '100',
                  '1000', '10123', '10311', '1000000', None)
     result_list = ('100', '1.000', '10.123', '10.311', '1.000.000',
                    '1.234.567,25', '100', '1.000', '10.123', '10.311',
                    '1.000.000', None)
     with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True):
         with translation.override('de'):
             self.humanize_tester(test_list, result_list, 'intcomma')
Exemplo n.º 3
0
 def test_inactive_user_i18n(self):
     with self.settings(USE_I18N=True):
         with translation.override('pt-br', deactivate=True):
             # The user is inactive.
             data = {
                 'username': '******',
                 'password': '******',
             }
             form = AuthenticationForm(None, data)
             self.assertFalse(form.is_valid())
             self.assertEqual(
                 form.non_field_errors(),
                 [force_unicode(form.error_messages['inactive'])])
 def render(self, context):
     if self.message_context:
         message_context = self.message_context.resolve(context)
     else:
         message_context = None
     tmp_context = {}
     for var, val in self.extra_context.items():
         tmp_context[var] = val.resolve(context)
     # Update() works like a push(), so corresponding context.pop() is at
     # the end of function
     context.update(tmp_context)
     singular, vars = self.render_token_list(self.singular)
     # Escape all isolated '%'
     singular = re.sub(u'%(?!\()', u'%%', singular)
     if self.plural and self.countervar and self.counter:
         count = self.counter.resolve(context)
         context[self.countervar] = count
         plural, plural_vars = self.render_token_list(self.plural)
         plural = re.sub(u'%(?!\()', u'%%', plural)
         if message_context:
             result = translation.npgettext(message_context, singular,
                                            plural, count)
         else:
             result = translation.ungettext(singular, plural, count)
         vars.extend(plural_vars)
     else:
         if message_context:
             result = translation.pgettext(message_context, singular)
         else:
             result = translation.ugettext(singular)
     data = dict([(v, _render_value_in_context(context.get(v, ''), context))
                  for v in vars])
     context.pop()
     try:
         result = result % data
     except KeyError:
         with translation.override(None):
             result = self.render(context)
     return result
 def test_flatpage_requires_trailing_slash_with_append_slash(self):
     form = FlatpageForm(data=dict(url='/no_trailing_slash', **self.form_data))
     with translation.override('en'):
         self.assertFalse(form.is_valid())
         self.assertEqual(form.errors['url'], ["URL is missing a trailing slash."])
 def render(self, context):
     with translation.override(self.language.resolve(context)):
         output = self.nodelist.render(context)
     return output
 def test_intcomma_without_number_grouping(self):
     # Regression for #17414
     with translation.override('ja'):
         with self.settings(USE_L10N=True):
             self.humanize_tester([100], ['100'], 'intcomma')