def test_ignore_entities(): """test that we don't get confused with entities and a & access key marker""" assert accesskey.extract(u"Set &browserName; as &Default") != ( u"Set &browserName; as &Default", u"b") assert accesskey.extract(u"Set &browserName; as &Default") == ( u"Set &browserName; as Default", u"D")
def applytranslation(key, propunit, inunit, mixedkeys): """applies the translation for key in the po unit to the prop unit""" # this converts the po-style string to a prop-style string value = inunit.target # handle mixed keys for labelsuffix in properties.labelsuffixes: if key.endswith(labelsuffix): if key in mixedkeys: value, akey = accesskey.extract(value) break else: for akeysuffix in properties.accesskeysuffixes: if key.endswith(akeysuffix): if key in mixedkeys: label, value = accesskey.extract(value) if not value: warnings.warn("Could not find accesskey for %s" % key) else: original = propunit.source # For the sake of diffs we keep the case of the # accesskey the same if we know the translation didn't # change. Casing matters in XUL. if value == propunit.source and original.lower() == value.lower(): if original.isupper(): value = value.upper() elif original.islower(): value = value.lower() return value
def applytranslation(entity, dtdunit, inputunit, mixedentities): """applies the translation for entity in the po unit to the dtd unit""" # this converts the po-style string to a dtd-style string unquotedstr = inputunit.target # check there aren't missing entities... if len(unquotedstr.strip()) == 0: return # handle mixed entities for labelsuffix in dtd.labelsuffixes: if entity.endswith(labelsuffix): if entity in mixedentities: unquotedstr, akey = accesskey.extract(unquotedstr) break else: for akeytype in dtd.accesskeysuffixes: if entity.endswith(akeytype): if entity in mixedentities: label, unquotedstr = accesskey.extract(unquotedstr) if not unquotedstr: warnings.warn("Could not find accesskey for %s" % entity) else: original = dtd.unquotefromdtd(dtdunit.definition) # For the sake of diffs we keep the case of the # accesskey the same if we know the translation didn't # change. Casing matters in XUL. if unquotedstr == dtdunit.source and original.lower() == unquotedstr.lower(): if original.isupper(): unquotedstr = unquotedstr.upper() elif original.islower(): unquotedstr = unquotedstr.lower() if len(unquotedstr) > 0: dtdunit.definition = dtd.quotefordtd(dtd.removeinvalidamps(entity, unquotedstr))
def applytranslation(entity, dtdunit, inputunit, mixedentities): """applies the translation for entity in the po unit to the dtd unit""" # this converts the po-style string to a dtd-style string unquotedstr = inputunit.target # check there aren't missing entities... if len(unquotedstr.strip()) == 0: return # handle mixed entities for labelsuffix in dtd.labelsuffixes: if entity.endswith(labelsuffix): if entity in mixedentities: unquotedstr, akey = accesskey.extract(unquotedstr) break else: for akeytype in dtd.accesskeysuffixes: if entity.endswith(akeytype): if entity in mixedentities: label, unquotedstr = accesskey.extract(unquotedstr) if not unquotedstr: warnings.warn("Could not find accesskey for %s" % entity) else: original = dtdunit.source # For the sake of diffs we keep the case of the # accesskey the same if we know the translation didn't # change. Casing matters in XUL. if unquotedstr == dtdunit.source and original.lower() == unquotedstr.lower(): if original.isupper(): unquotedstr = unquotedstr.upper() elif original.islower(): unquotedstr = unquotedstr.lower() if len(unquotedstr) > 0: dtdunit.source = dtd.removeinvalidamps(entity, unquotedstr)
def applytranslation(key, propunit, inunit, mixedkeys): """applies the translation for key in the po unit to the prop unit""" # this converts the po-style string to a prop-style string value = inunit.target # handle mixed keys for labelsuffix in properties.labelsuffixes: if key.endswith(labelsuffix): if key in mixedkeys: value, akey = accesskey.extract(value) break else: for akeysuffix in properties.accesskeysuffixes: if key.endswith(akeysuffix): if key in mixedkeys: label, value = accesskey.extract(value) if not value: warnings.warn("Could not find accesskey for %s" % key) # Use the source language accesskey label, value = accesskey.extract(inunit.source) else: original = propunit.source # For the sake of diffs we keep the case of the # accesskey the same if we know the translation didn't # change. Casing matters in XUL. if value == propunit.source and original.lower() == value.lower(): if original.isupper(): value = value.upper() elif original.islower(): value = value.lower() return value
def test_unicode(): """test that we can do the same with unicode strings""" assert accesskey.extract(u"Eḓiṱ") == (u"Eḓiṱ", u"") assert accesskey.extract(u"E&ḓiṱ") == (u"Eḓiṱ", u"ḓ") assert accesskey.extract(u"E_ḓiṱ", u"_") == (u"Eḓiṱ", u"ḓ") label, akey = accesskey.extract(u"E&ḓiṱ") assert label, akey == (u"Eḓiṱ", u"ḓ") assert isinstance(label, unicode) and isinstance(akey, unicode)
def test_get_label_and_accesskey(): """test that we can extract the label and accesskey components from an accesskey+label string""" assert accesskey.extract(u"") == (u"", u"") assert accesskey.extract(u"File") == (u"File", u"") assert accesskey.extract(u"&File") == (u"File", u"F") assert accesskey.extract(u"~File", u"~") == (u"File", u"F") assert accesskey.extract(u"_File", u"_") == (u"File", u"F")
def test_unicode(): """test that we can do the same with unicode strings""" assert accesskey.extract("Eḓiṱ") == ("Eḓiṱ", "") assert accesskey.extract("E&ḓiṱ") == ("Eḓiṱ", "ḓ") assert accesskey.extract("E_ḓiṱ", "_") == ("Eḓiṱ", "ḓ") label, akey = accesskey.extract("E&ḓiṱ") assert label, akey == ("Eḓiṱ", "ḓ") assert isinstance(label, str) and isinstance(akey, str) assert accesskey.combine("Eḓiṱ", "ḓ") == ("E&ḓiṱ")
def test_end_of_string(): """test that we can handle an accesskey at the end of the string""" assert accesskey.extract(u"Hlola&") == (u"Hlola&", u"")
def test_extract_bad_accesskeys(): """Test what we do in situations that are bad fof accesskeys""" # Space is not valid accesskey so we don't extract anything assert accesskey.extract(u"More& Whitespace") == (u"More& Whitespace", u"")
def test_empty_string(): """test that we can handle and empty label+accesskey string""" assert accesskey.extract(u"") == (u"", u"") assert accesskey.extract(u"", u"~") == (u"", u"")
def test_alternate_accesskey_marker(): """check that we can identify the accesskey if the marker is different""" assert accesskey.extract(u"~File", u"~") == (u"File", u"F") assert accesskey.extract(u"&File", u"~") == (u"&File", u"")
def test_numeric(): """test combining and extracting numeric markers""" assert accesskey.extract(u"&100%") == (u"100%", u"1") assert accesskey.combine(u"100%", u"1") == u"&100%"
def test_accesskey_already_in_text(): """test that we can combine if the accesskey is already in the text""" assert accesskey.combine(u"Mail & Newsgroups", u"N") == u"Mail & &Newsgroups" assert accesskey.extract(u"Mail & &Newsgroups") == (u"Mail & Newsgroups", u"N")
def test_extract_bad_accesskeys(): """Test what we do in situations that are bad fof accesskeys""" # Space is not valid accesskey so we don't extract anything assert accesskey.extract("More& Whitespace") == ("More& Whitespace", "")
def test_ignore_entities(): """test that we don't get confused with entities and a & access key marker""" assert accesskey.extract(u"Set &browserName; as &Default") != (u"Set &browserName; as &Default", u"b") assert accesskey.extract(u"Set &browserName; as &Default") == (u"Set &browserName; as Default", u"D")