def get_toolbar(self, language, fieldname, unit, idx): """ Returns toolbar HTML code. """ groups = [] if idx: append = '?plural=1' else: append = '' # Copy button extra_params = COPY_TEMPLATE.format( ugettext(u'Loading…'), ''.join(( reverse('js-get', kwargs={'unit_id': unit.id}), append, )), unit.checksum, ) groups.append( GROUP_TEMPLATE.format( '', BUTTON_TEMPLATE.format( 'copy-text', ugettext('Fill in with source string'), extra_params, ICON_TEMPLATE.format('clipboard', ugettext('Copy'))))) # Special chars chars = [] for name, char in get_special_chars(language): chars.append(BUTTON_TEMPLATE.format('specialchar', name, '', char)) groups.append(GROUP_TEMPLATE.format('', u'\n'.join(chars))) # RTL/LTR switch if language.direction == 'rtl': rtl_name = 'rtl-{0}'.format(fieldname) rtl_switch = [ RADIO_TEMPLATE.format( 'direction-toggle active', ugettext('Toggle text direction'), rtl_name, 'rtl', 'checked="checked"', 'RTL', ), RADIO_TEMPLATE.format('direction-toggle', ugettext('Toggle text direction'), rtl_name, 'ltr', '', 'LTR'), ] groups.append( GROUP_TEMPLATE.format('data-toggle="buttons"', u'\n'.join(rtl_switch))) return TOOLBAR_TEMPLATE.format(u'\n'.join(groups))
def get_toolbar(self, language, fieldname, unit, idx): """Return toolbar HTML code.""" profile = self.profile groups = [] plurals = unit.get_source_plurals() if idx and len(plurals) > 1: source = plurals[1] else: source = plurals[0] # Copy button extra_params = COPY_TEMPLATE.format( escape(ugettext('Loading…')), unit.checksum, escape(json.dumps(source)) ) groups.append( GROUP_TEMPLATE.format( '', BUTTON_TEMPLATE.format( 'copy-text', ugettext('Fill in with source string'), extra_params, ICON_TEMPLATE.format('clipboard', ugettext('Copy')) ) ) ) # Special chars chars = [ BUTTON_TEMPLATE.format( 'specialchar', name, 'data-value="{}"'.format( value.encode('ascii', 'xmlcharrefreplace').decode('ascii') ), char ) for name, char, value in get_special_chars(language, profile.special_chars) ] groups.append( GROUP_TEMPLATE.format('', '\n'.join(chars)) ) result = TOOLBAR_TEMPLATE.format('\n'.join(groups)) if language.direction == 'rtl': result = self.get_rtl_toolbar(fieldname) + result return result
def get_toolbar(self, language, fieldname, unit, idx): """ Returns toolbar HTML code. """ profile = self.profile groups = [] plurals = unit.get_source_plurals() if idx and len(plurals) > 1: source = plurals[1] else: source = plurals[0] # Copy button extra_params = COPY_TEMPLATE.format(escape(ugettext('Loading…')), unit.checksum, escape(json.dumps(source))) groups.append( GROUP_TEMPLATE.format( '', BUTTON_TEMPLATE.format( 'copy-text', ugettext('Fill in with source string'), extra_params, ICON_TEMPLATE.format('clipboard', ugettext('Copy'))))) # Special chars chars = [] for name, char in get_special_chars(language, profile.special_chars): chars.append(BUTTON_TEMPLATE.format('specialchar', name, '', char)) groups.append(GROUP_TEMPLATE.format('', '\n'.join(chars))) # RTL/LTR switch if language.direction == 'rtl': rtl_name = 'rtl-{0}'.format(fieldname) rtl_switch = [ RADIO_TEMPLATE.format( 'direction-toggle active', ugettext('Toggle text direction'), rtl_name, 'rtl', 'checked="checked"', 'RTL', ), RADIO_TEMPLATE.format('direction-toggle', ugettext('Toggle text direction'), rtl_name, 'ltr', '', 'LTR'), ] groups.append( GROUP_TEMPLATE.format('data-toggle="buttons"', '\n'.join(rtl_switch))) return TOOLBAR_TEMPLATE.format('\n'.join(groups))
def get_toolbar(self, language, fieldname, unit, idx): """ Returns toolbar HTML code. """ groups = [] if idx: append = "?plural=1" else: append = "" # Copy button extra_params = COPY_TEMPLATE.format( ugettext(u"Loading…"), "".join((reverse("js-get", kwargs={"unit_id": unit.id}), append)), unit.checksum ) groups.append( GROUP_TEMPLATE.format( "", BUTTON_TEMPLATE.format( "copy-text", ugettext("Fill in with source string"), extra_params, ICON_TEMPLATE.format("clipboard", ugettext("Copy")), ), ) ) # Special chars chars = [] for name, char in get_special_chars(language): chars.append(BUTTON_TEMPLATE.format("specialchar", name, "", char)) groups.append(GROUP_TEMPLATE.format("", u"\n".join(chars))) # RTL/LTR switch if language.direction == "rtl": rtl_name = "rtl-{0}".format(fieldname) rtl_switch = [ RADIO_TEMPLATE.format( "direction-toggle active", ugettext("Toggle text direction"), rtl_name, "rtl", 'checked="checked"', "RTL", ), RADIO_TEMPLATE.format( "direction-toggle", ugettext("Toggle text direction"), rtl_name, "ltr", "", "LTR" ), ] groups.append(GROUP_TEMPLATE.format('data-toggle="buttons"', u"\n".join(rtl_switch))) return TOOLBAR_TEMPLATE.format(u"\n".join(groups))
def test_brx(self): chars = list(get_special_chars(Language(code='brx'))) self.assertEqual(len(chars), 9)
def test_af(self): chars = list(get_special_chars(Language(code='af'))) self.assertEqual(len(chars), 10)
def test_settings(self): chars = list(get_special_chars(Language(code='cs'))) self.assertEqual(len(chars), 262)
def test_brx_add(self): chars = list(get_special_chars(Language(code='brx'), 'ahoj')) self.assertEqual(len(chars), 13)
def get_toolbar(self, language, fieldname, unit, idx): """ Returns toolbar HTML code. """ groups = [] plurals = unit.get_source_plurals() if idx and len(plurals) > 1: source = plurals[1] else: source = plurals[0] # Copy button extra_params = COPY_TEMPLATE.format( escape(ugettext('Loading…')), unit.checksum, escape(json.dumps(source)) ) groups.append( GROUP_TEMPLATE.format( '', BUTTON_TEMPLATE.format( 'copy-text', ugettext('Fill in with source string'), extra_params, ICON_TEMPLATE.format('clipboard', ugettext('Copy')) ) ) ) # Special chars chars = [] for name, char in get_special_chars(language): chars.append( BUTTON_TEMPLATE.format( 'specialchar', name, '', char ) ) groups.append( GROUP_TEMPLATE.format('', '\n'.join(chars)) ) # RTL/LTR switch if language.direction == 'rtl': rtl_name = 'rtl-{0}'.format(fieldname) rtl_switch = [ RADIO_TEMPLATE.format( 'direction-toggle active', ugettext('Toggle text direction'), rtl_name, 'rtl', 'checked="checked"', 'RTL', ), RADIO_TEMPLATE.format( 'direction-toggle', ugettext('Toggle text direction'), rtl_name, 'ltr', '', 'LTR' ), ] groups.append( GROUP_TEMPLATE.format( 'data-toggle="buttons"', '\n'.join(rtl_switch) ) ) return TOOLBAR_TEMPLATE.format('\n'.join(groups))
def test_brx_add(self): chars = list(get_special_chars(Language(code="brx"), "ahoj")) self.assertEqual(len(chars), 14)
def test_cs(self): chars = list(get_special_chars(Language(code="cs"))) self.assertEqual(len(chars), 10)
def check_chars(self, language, count, matches, *args, **kwargs): result = get_special_chars(language, *args, **kwargs) chars = set((x[2] for x in result)) self.assertEqual(len(chars), count) for match in matches: self.assertIn(match, chars)
def get_toolbar(self, language, fieldname, checksum): """ Returns toolbar HTML code. """ groups = [] # Copy button extra_params = u'data-loading-text="{0}" data-href="{1}"'.format( ugettext(u'Loading…'), reverse('js-get', kwargs={'checksum': checksum}), ) groups.append( GROUP_TEMPLATE.format( '', BUTTON_TEMPLATE.format( 'copy-text', ugettext('Fill in with source string'), extra_params, ICON_TEMPLATE.format('transfer', ugettext('Copy')) ) ) ) # Special chars chars = [] for name, char in get_special_chars(language): chars.append( BUTTON_TEMPLATE.format( 'specialchar', name, '', char ) ) groups.append( GROUP_TEMPLATE.format('', u'\n'.join(chars)) ) # RTL/LTR switch if language.direction == 'rtl': rtl_name = 'rtl-{0}'.format(fieldname) rtl_switch = [ RADIO_TEMPLATE.format( 'direction-toggle active', ugettext('Toggle text direction'), rtl_name, 'rtl', 'checked="checked"', 'RTL', ), RADIO_TEMPLATE.format( 'direction-toggle', ugettext('Toggle text direction'), rtl_name, 'ltr', '', 'LTR' ), ] groups.append( GROUP_TEMPLATE.format( 'data-toggle="buttons"', u'\n'.join(rtl_switch) ) ) return TOOLBAR_TEMPLATE.format(u'\n'.join(groups))
def check_chars(self, language, count, matches, *args, **kwargs): result = get_special_chars(language, *args, **kwargs) chars = {x[2] for x in result} self.assertEqual(len(chars), count) for match in matches: self.assertIn(match, chars)
def get_toolbar(self, language, fieldname, unit, idx): """ Returns toolbar HTML code. """ groups = [] if idx: append = '?plural=1' else: append = '' # Copy button extra_params = COPY_TEMPLATE.format( ugettext('Loading…'), ''.join(( reverse('js-get', kwargs={'unit_id': unit.id}), append, )), unit.checksum, ) groups.append( GROUP_TEMPLATE.format( '', BUTTON_TEMPLATE.format( 'copy-text', ugettext('Fill in with source string'), extra_params, ICON_TEMPLATE.format('clipboard', ugettext('Copy')) ) ) ) # Special chars chars = [] for name, char in get_special_chars(language): chars.append( BUTTON_TEMPLATE.format( 'specialchar', name, '', char ) ) groups.append( GROUP_TEMPLATE.format('', '\n'.join(chars)) ) # RTL/LTR switch if language.direction == 'rtl': rtl_name = 'rtl-{0}'.format(fieldname) rtl_switch = [ RADIO_TEMPLATE.format( 'direction-toggle active', ugettext('Toggle text direction'), rtl_name, 'rtl', 'checked="checked"', 'RTL', ), RADIO_TEMPLATE.format( 'direction-toggle', ugettext('Toggle text direction'), rtl_name, 'ltr', '', 'LTR' ), ] groups.append( GROUP_TEMPLATE.format( 'data-toggle="buttons"', '\n'.join(rtl_switch) ) ) return TOOLBAR_TEMPLATE.format('\n'.join(groups))