changes
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -287,7 +287,7 @@ class DocumentGenerator:
|
||||
return str(val)
|
||||
if fmt_type == "number_to_words":
|
||||
try:
|
||||
return num2words(val, lang=fmt.get("lang", "en"))
|
||||
return num2words(val, lang=fmt.get("lang", "vi"))
|
||||
except Exception:
|
||||
return str(val)
|
||||
if fmt_type == "conditional":
|
||||
@@ -397,16 +397,37 @@ class DocumentGenerator:
|
||||
return placeholders
|
||||
|
||||
def _parse_format_args(self, args_string):
|
||||
"""Parses a string like 'lang:vi, type:number_to_words' into a dictionary."""
|
||||
if not args_string:
|
||||
return {}
|
||||
format_config = {}
|
||||
args = args_string.split(',')
|
||||
for arg in args:
|
||||
if ':' in arg:
|
||||
key, value = arg.split(':', 1)
|
||||
format_config[key.strip()] = value.strip()
|
||||
return format_config
|
||||
|
||||
parts = [p.strip() for p in args_string.split(',')]
|
||||
root = {}
|
||||
current = root
|
||||
|
||||
for part in parts:
|
||||
if ':' not in part:
|
||||
continue
|
||||
|
||||
key, value = part.split(':', 1)
|
||||
key = key.strip()
|
||||
value = value.strip()
|
||||
|
||||
if key == "next":
|
||||
# nếu next chưa tồn tại thì tạo
|
||||
if "next" not in current or not isinstance(current["next"], dict):
|
||||
current["next"] = {}
|
||||
current = current["next"]
|
||||
|
||||
# hỗ trợ next:type:number_to_words
|
||||
if ':' in value:
|
||||
sub_key, sub_val = value.split(':', 1)
|
||||
current[sub_key.strip()] = sub_val.strip()
|
||||
else:
|
||||
current[key] = value
|
||||
|
||||
return root
|
||||
|
||||
|
||||
|
||||
def prepare_replacements(self, doc):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user