From e64cd21f6fbe738a200a160d2a5f57597d536cbc Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 18 Mar 2022 00:27:20 +0800 Subject: Remap property path based on path substrings Also added captialization caching. --- editor/translations/extract.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'editor/translations/extract.py') diff --git a/editor/translations/extract.py b/editor/translations/extract.py index 65d1341e9e..5f68d7702e 100755 --- a/editor/translations/extract.py +++ b/editor/translations/extract.py @@ -87,17 +87,24 @@ capitalize_re = re.compile(r"(?<=\D)(?=\d)|(?<=\d)(?=\D([a-z]|\d))") def _process_editor_string(name): - # See String::capitalize(). - # fmt: off - capitalized = " ".join( - part.title() - for part in capitalize_re.sub("_", name).replace("_", " ").split() - ) - # fmt: on - # See EditorStringProcessor::process_string(). - for key, value in remaps.items(): - capitalized = capitalized.replace(key, value) - return capitalized + # See EditorPropertyNameProcessor::process_string(). + capitalized_parts = [] + for segment in name.split("_"): + if not segment: + continue + remapped = remaps.get(segment) + if remapped: + capitalized_parts.append(remapped) + else: + # See String::capitalize(). + # fmt: off + capitalized_parts.append(" ".join( + part.title() + for part in capitalize_re.sub("_", segment).replace("_", " ").split() + )) + # fmt: on + + return " ".join(capitalized_parts) def _write_message(msgctx, msg, msg_plural, location): -- cgit v1.2.3