fix pymacro not using custom defined plurals

This commit is contained in:
Akbar Rahman 2021-03-07 11:44:30 +00:00
parent 7f19892571
commit 10d0b76087

View File

@ -26,8 +26,18 @@ def get_args():
return parser.parse_args()
def pluralize(word):
def pluralize(input):
""" Returns the plural form of a word. """
if isinstance(input, list):
# use custom plural if defined
if len(input) > 1:
return input[1]
return pluralize_word(input[0])
return pluralize_word(input)
def pluralize_word(word):
def is_vowel(letter):
if not isinstance(letter, str):
raise ValueError("Argument 'letter' must be type str")
@ -35,7 +45,6 @@ def pluralize(word):
raise ValueError("Argument 'letter' must be 1 long")
return letter in 'aeiou'
# TODO add more complex plural forms
if word[-1] in 'sxz' or word[-2:] in ['ch', 'sh']:
return word + 'es'
@ -130,7 +139,7 @@ def process(input, macros):
value = token
if token.lower() in macros.keys():
value = macros[token.lower()]
value = macros[token.lower()][0]
elif token.lower() in [f"{m}s" for m in macros.keys()]:
value = pluralize(macros[token.lower()[:-1]])
@ -193,7 +202,7 @@ def get_macros(input, child=False):
# store macros as dict and return
for index, macro in enumerate(macros):
if len(macro) >= 2:
response[macro[0].lower()] = macro[1]
response[macro[0].lower()] = macro[1:]
return response
def is_otf_macro_start(token, line):