Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customizable entries #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Strandinator
Copy link

Hi there.
For our use case we have specific formatting of the occurrences section in .po files.
So i made POEntry and _BaseEntry easier to customize

With these adjustments i can define a custom POFile that creates custom POEntry elements.
(I am no python expert. Not sure if I could write this in one line)

class CustomPOFile(polib.POFile):

    def append(self, entry: polib.POEntry) -> None:
        custom = CustomPOEntry(wrapwidth=self.wrapwidth)

        custom.msgid = entry.msgid
        custom.msgstr = entry.msgstr
        custom.msgid_plural = entry.msgid_plural
        custom.msgstr_plural = entry.msgstr_plural
        custom.msgctxt = entry.msgctxt
        custom.obsolete = entry.obsolete
        custom.encoding = entry.encoding
        custom.comment = entry.comment
        custom.tcomment = entry.tcomment
        custom.occurrences = entry.occurrences
        custom.flags = entry.flags
        custom.previous_msgctxt = entry.previous_msgctxt
        custom.previous_msgid = entry.previous_msgid
        custom.previous_msgid_plural = entry.previous_msgid_plural
        custom.linenum = entry.linenum

        return super().append(custom)

And in my custom POEntry i can overwrite methods with my custom implementation:

class CustomPOEntry(polib.POEntry):

    def _unicode_occurrences(self, ret, **kwargs):
        # custom stuff
        # ret += [...]
        pass

Let me know if you would do something else. (also naming)
As I said: not a python expert.

@Strandinator
Copy link
Author

To be clear. I could use this approach before. I just had replace the whole POEntry.__unicode__ implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant