izimobil / polib

Pure python library to manipulate, create, modify gettext files (pot, po and mo files).
MIT License
100 stars 28 forks source link

Allow more control comparing PO entries #108

Open mondeja opened 3 years ago

mondeja commented 3 years ago

I've a case in which I'm comparing PO entries without take into account msgstr neither obsolete. Currently, I'm duplicating the POEntry.__cmp__ function adding optional parameters compare_obsolete and compare_msgstr. Could this be added to polib, maybe adding other parameters for msgstr_plural, msgid...?


class Foo:
    def __cmp__(self, other, are_equal=False, other_are_equal=False):
        if are_equal or other_are_equal:
            return True
        return False

a = Foo()
b = Foo()

print(a == b)                                                  # False
print(a != b)                                                  # True
print(a.__cmp__(b))                                            # False
print(a.__cmp__(b, are_equal=False, other_are_equal=True))     # True
print(a.__cmp__(b, are_equal=True, other_are_equal=False))     # True