Пример #1
0
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")
Пример #2
0
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
Пример #3
0
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))
Пример #4
0
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)
Пример #5
0
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
Пример #6
0
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)
Пример #7
0
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")
Пример #8
0
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")
Пример #9
0
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)
Пример #10
0
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ṱ")
Пример #11
0
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"")
Пример #12
0
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"")
Пример #13
0
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"")
Пример #14
0
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"")
Пример #15
0
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%"
Пример #16
0
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")
Пример #17
0
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", "")
Пример #18
0
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")
Пример #19
0
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"")
Пример #20
0
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%"
Пример #21
0
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"")
Пример #22
0
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"")
Пример #23
0
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")