This commit is contained in:
anhduy-tech
2026-01-15 13:57:23 +07:00
parent 2d4d2d10a0
commit ae5326b618
7 changed files with 31 additions and 9 deletions

View File

@@ -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):
"""

View File

@@ -0,0 +1 @@
,kumduy,duy-pc,15.01.2026 12:11,file:///home/kumduy/.config/libreoffice/4;