mirror of
https://github.com/alvierahman90/otfmacros.git
synced 2024-12-15 12:01:59 +00:00
Add custom plural support
This commit is contained in:
parent
4fd09033aa
commit
0b5db86c83
11
pymacro
11
pymacro
@ -18,10 +18,15 @@ def get_args():
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def pluralize(word):
|
def pluralize(word, macro=None):
|
||||||
"""
|
"""
|
||||||
Returns the plural form of a word.
|
Returns the plural form of a word.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if macro:
|
||||||
|
if len(macro) == 3:
|
||||||
|
return macro[2]
|
||||||
|
|
||||||
# TODO add more complex plural forms
|
# TODO add more complex plural forms
|
||||||
if word[-1] in 'sxz' or word[-2:] in ['ch', 'sh']:
|
if word[-1] in 'sxz' or word[-2:] in ['ch', 'sh']:
|
||||||
return word + 'es'
|
return word + 'es'
|
||||||
@ -83,7 +88,7 @@ def process(tokens, macros):
|
|||||||
elif macro[0].lower() + 's' == token.lower():
|
elif macro[0].lower() + 's' == token.lower():
|
||||||
match = True
|
match = True
|
||||||
plural = True
|
plural = True
|
||||||
value = pluralize(macro[1])
|
value = pluralize(macro[1], macro=macro)
|
||||||
break
|
break
|
||||||
|
|
||||||
output[line_number][token_number] = upper_check(token, value)
|
output[line_number][token_number] = upper_check(token, value)
|
||||||
@ -117,7 +122,7 @@ def get_macros(input):
|
|||||||
|
|
||||||
# validate macros
|
# validate macros
|
||||||
for index, macro in enumerate(macros):
|
for index, macro in enumerate(macros):
|
||||||
if len(macro) == 2:
|
if len(macro) == 2 or len(macro) == 3:
|
||||||
macros[index] = tuple(macros[index])
|
macros[index] = tuple(macros[index])
|
||||||
else:
|
else:
|
||||||
macros.pop(index)
|
macros.pop(index)
|
||||||
|
Loading…
Reference in New Issue
Block a user