Last active
September 22, 2025 14:31
-
-
Save Vocaned/75780c108836e71a440614a29652d83f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| init -1 python: | |
| DICTIONARY = { | |
| r'\bfoot\b': 'paw', | |
| r'\bfeet\b': 'paws' | |
| } | |
| # Python 2.7 has unordered dictionaries, convert to list instead | |
| keys = list(DICTIONARY.keys()) | |
| import re | |
| regex_parts = [] | |
| for i, k in enumerate(keys): | |
| regex_parts.append("(?P<k{0}>{1})".format(i, k)) | |
| regex = re.compile("|".join(regex_parts), re.IGNORECASE) | |
| def match(m): | |
| key = keys[int(m.lastgroup[1:])] | |
| origword = m.group(0) | |
| replacement = DICTIONARY[key] | |
| if origword.isupper(): | |
| return replacement.upper() | |
| if origword.islower(): | |
| return replacement.lower() | |
| if origword.istitle(): | |
| return replacement.title() | |
| return replacement | |
| from renpy.text.text import Text | |
| orig_init = Text.__init__ | |
| def patch(self, text, *args, **kwargs): | |
| orig_init(self, regex.sub(match, text), *args, **kwargs) | |
| Text.__init__ = patch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment