def localization_check_in_meta(): class TableNoLocalize(tables.Table): name = tables.Column(verbose_name="my column") class Meta: default = "---" class TableLocalize(tables.Table): name = tables.Column(verbose_name="my column") class Meta: default = "---" localize = ('name',) class TableUnlocalize(tables.Table): name = tables.Column(verbose_name="my column") class Meta: default = "---" unlocalize = ('name',) class TableLocalizePrecedence(tables.Table): name = tables.Column(verbose_name="my column") class Meta: default = "---" unlocalize = ('name',) localize = ('name',) simple_test_data = [{'name': 1234.5}] expected_reults = { None: '1234.5', False: '1234.5', True: '1{0}234,5'.format(' ') # non-breaking space } # No localize html = TableNoLocalize(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[None]) in html with settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True): with translation("pl"): # the same as in localization_check. # with localization and polish locale we get formatted output html = TableNoLocalize(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[True]) in html # localize html = TableLocalize(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[True]) in html # unlocalize html = TableUnlocalize(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[False]) in html # test unlocalize higher precedence html = TableLocalizePrecedence(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[False]) in html
def localization_check(): def get_cond_localized_table(localizeit=None): ''' helper function for defining Table class conditionally ''' class TestTable(tables.Table): name = tables.Column(verbose_name="my column", localize=localizeit) return TestTable simple_test_data = [{'name': 1234.5}] expected_reults = { None: '1234.5', False: '1234.5', True: '1 234,5' # non-breaking space } # no localization html = get_cond_localized_table(None)(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[None]) in html # unlocalize html = get_cond_localized_table(False)(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[False]) in html with settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True): with translation("pl"): # with default polish locales and enabled thousand separator # 1234.5 is formatted as "1 234,5" with nbsp html = get_cond_localized_table(True)(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format( expected_reults[True]) in html # with localize = False there should be no formatting html = get_cond_localized_table(False)(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format( expected_reults[False]) in html # with localize = None and USE_L10N = True # there should be the same formatting as with localize = True html = get_cond_localized_table(None)(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format( expected_reults[True]) in html
def localization_check(): def get_cond_localized_table(localizeit=None): ''' helper function for defining Table class conditionally ''' class TestTable(tables.Table): name = tables.Column(verbose_name="my column", localize=localizeit) return TestTable simple_test_data = [{'name': 1234.5}] expected_reults = { None: '1234.5', False: '1234.5', True: '1 234,5' # non-breaking space } # no localization html = get_cond_localized_table(None)(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[None]) in html # unlocalize html = get_cond_localized_table(False)(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[False]) in html with settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True): with translation("pl"): # with default polish locales and enabled thousand separator # 1234.5 is formatted as "1 234,5" with nbsp html = get_cond_localized_table(True)(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[True]) in html # with localize = False there should be no formatting html = get_cond_localized_table(False)(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[False]) in html # with localize = None and USE_L10N = True # there should be the same formatting as with localize = True html = get_cond_localized_table(None)(simple_test_data).as_html() assert '<td class="name">{0}</td>'.format(expected_reults[True]) in html
def translation_works(): assert ugettext("the apple") == "the apple" with translation("de"): assert ugettext("the apple") == "der Apfel" with translation("en"): assert ugettext("the apple") == "the apple"