From 1bf30d7be0fce53a934966779f09f2a3335d63aa Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Sun, 20 Mar 2022 20:21:05 +0800 Subject: [PATCH] More editor `extract.py` improvements and fixes --- editor/editor_property_name_processor.cpp | 20 +++++++++++++++++--- editor/translations/extract.py | 21 ++++++++++++--------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/editor/editor_property_name_processor.cpp b/editor/editor_property_name_processor.cpp index 49f2f210953..f55b2b61c83 100644 --- a/editor/editor_property_name_processor.cpp +++ b/editor/editor_property_name_processor.cpp @@ -83,6 +83,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() { capitalize_string_remaps["aabb"] = "AABB"; capitalize_string_remaps["adb"] = "ADB"; capitalize_string_remaps["ao"] = "AO"; + capitalize_string_remaps["apk"] = "APK"; capitalize_string_remaps["arvr"] = "ARVR"; capitalize_string_remaps["bg"] = "BG"; capitalize_string_remaps["bp"] = "BP"; @@ -119,15 +120,21 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() { capitalize_string_remaps["hsv"] = "HSV"; capitalize_string_remaps["http"] = "HTTP"; capitalize_string_remaps["id"] = "ID"; - capitalize_string_remaps["ik"] = "IK"; capitalize_string_remaps["igd"] = "IGD"; + capitalize_string_remaps["ik"] = "IK"; + capitalize_string_remaps["image@2x"] = "Image @2x"; + capitalize_string_remaps["image@3x"] = "Image @3x"; capitalize_string_remaps["ios"] = "iOS"; capitalize_string_remaps["iod"] = "IOD"; capitalize_string_remaps["ip"] = "IP"; + capitalize_string_remaps["ipad"] = "iPad"; + capitalize_string_remaps["iphone"] = "iPhone"; capitalize_string_remaps["ipv6"] = "IPv6"; + capitalize_string_remaps["jit"] = "JIT"; capitalize_string_remaps["k1"] = "K1"; capitalize_string_remaps["k2"] = "K2"; capitalize_string_remaps["kb"] = "(KB)"; // Unit. + capitalize_string_remaps["ldr"] = "LDR"; capitalize_string_remaps["lod"] = "LOD"; capitalize_string_remaps["lowpass"] = "Low-pass"; capitalize_string_remaps["macos"] = "macOS"; @@ -137,13 +144,16 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() { //capitalize_string_remaps["msec"] = "(msec)"; // Unit. capitalize_string_remaps["msaa"] = "MSAA"; capitalize_string_remaps["normalmap"] = "Normal Map"; + capitalize_string_remaps["ok"] = "OK"; capitalize_string_remaps["opengl"] = "OpenGL"; capitalize_string_remaps["opentype"] = "OpenType"; capitalize_string_remaps["openxr"] = "OpenXR"; + capitalize_string_remaps["pck"] = "PCK"; capitalize_string_remaps["png"] = "PNG"; capitalize_string_remaps["po2"] = "(Power of 2)"; // Unit. capitalize_string_remaps["pvs"] = "PVS"; capitalize_string_remaps["pvrtc"] = "PVRTC"; + capitalize_string_remaps["rgb"] = "RGB"; capitalize_string_remaps["rid"] = "RID"; capitalize_string_remaps["rmb"] = "RMB"; capitalize_string_remaps["rpc"] = "RPC"; @@ -152,18 +162,21 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() { capitalize_string_remaps["sdfgi"] = "SDFGI"; capitalize_string_remaps["sdk"] = "SDK"; capitalize_string_remaps["sec"] = "(sec)"; // Unit. + capitalize_string_remaps["srgb"] = "sRGB"; capitalize_string_remaps["ssao"] = "SSAO"; capitalize_string_remaps["ssh"] = "SSH"; capitalize_string_remaps["ssil"] = "SSIL"; capitalize_string_remaps["ssl"] = "SSL"; capitalize_string_remaps["stderr"] = "stderr"; capitalize_string_remaps["stdout"] = "stdout"; + capitalize_string_remaps["svg"] = "SVG"; capitalize_string_remaps["tcp"] = "TCP"; capitalize_string_remaps["ui"] = "UI"; capitalize_string_remaps["url"] = "URL"; capitalize_string_remaps["urls"] = "URLs"; - capitalize_string_remaps["us"] = "(µs)"; // Unit. - capitalize_string_remaps["usec"] = "(µsec)"; // Unit. + capitalize_string_remaps["us"] = String::utf8("(µs)"); // Unit. + capitalize_string_remaps["usec"] = String::utf8("(µsec)"); // Unit. + capitalize_string_remaps["uuid"] = "UUID"; capitalize_string_remaps["uv"] = "UV"; capitalize_string_remaps["uv1"] = "UV1"; capitalize_string_remaps["uv2"] = "UV2"; @@ -174,6 +187,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() { capitalize_string_remaps["webp"] = "WebP"; capitalize_string_remaps["webrtc"] = "WebRTC"; capitalize_string_remaps["websocket"] = "WebSocket"; + capitalize_string_remaps["wifi"] = "Wi-Fi"; capitalize_string_remaps["xr"] = "XR"; capitalize_string_remaps["xy"] = "XY"; capitalize_string_remaps["xz"] = "XZ"; diff --git a/editor/translations/extract.py b/editor/translations/extract.py index e26016d108b..dc7880a7026 100755 --- a/editor/translations/extract.py +++ b/editor/translations/extract.py @@ -34,12 +34,12 @@ matches.sort() remaps = {} -remap_re = re.compile(r'capitalize_string_remaps\["(.+)"\] = "(.+)";') +remap_re = re.compile(r'^\t*capitalize_string_remaps\["(?P.+)"\] = (String::utf8\()?"(?P.+)"') with open("editor/editor_property_name_processor.cpp") as f: for line in f: m = remap_re.search(line) if m: - remaps[m.group(1)] = m.group(2) + remaps[m.group("from")] = m.group("to") unique_str = [] @@ -70,16 +70,19 @@ class ExtractType(enum.IntEnum): GROUP = 3 -# Regex "(?P(?:[^"\\]|\\.)*)" creates a group named `name` that matches a string. +# Regex "(?P([^"\\]|\\.)*)" creates a group named `name` that matches a string. message_patterns = { - re.compile(r'RTR\("(?P(?:[^"\\]|\\.)*)"\)'): ExtractType.TEXT, - re.compile(r'TTR\("(?P(?:[^"\\]|\\.)*)"(?:, "(?P(?:[^"\\]|\\.)*)")?\)'): ExtractType.TEXT, - re.compile(r'TTRC\("(?P(?:[^"\\]|\\.)*)"\)'): ExtractType.TEXT, + re.compile(r'RTR\("(?P([^"\\]|\\.)*)"\)'): ExtractType.TEXT, + re.compile(r'TTR\("(?P([^"\\]|\\.)*)"(, "(?P([^"\\]|\\.)*)")?\)'): ExtractType.TEXT, + re.compile(r'TTRC\("(?P([^"\\]|\\.)*)"\)'): ExtractType.TEXT, re.compile(r'_initial_set\("(?P[^"]+?)",'): ExtractType.PROPERTY_PATH, - re.compile(r'GLOBAL_DEF(?:_RST)?\("(?P[^".]+?)",'): ExtractType.PROPERTY_PATH, - re.compile(r'EDITOR_DEF(?:_RST)?\("(?P[^"]+?)",'): ExtractType.PROPERTY_PATH, + re.compile(r'GLOBAL_DEF(_RST)?(_NOVAL)?\("(?P[^".]+?)",'): ExtractType.PROPERTY_PATH, + re.compile(r'EDITOR_DEF(_RST)?\("(?P[^"]+?)",'): ExtractType.PROPERTY_PATH, re.compile( - r'ADD_PROPERTY\(PropertyInfo\(Variant::[_A-Z0-9]+, "(?P[^"]+?)"[,)]' + r'(ADD_PROPERTYI?|ImportOption|ExportOption)\(PropertyInfo\(Variant::[_A-Z0-9]+, "(?P[^"]+?)"[,)]' + ): ExtractType.PROPERTY_PATH, + re.compile( + r"(?!#define )LIMPL_PROPERTY(_RANGE)?\(Variant::[_A-Z0-9]+, (?P[^,]+?)," ): ExtractType.PROPERTY_PATH, re.compile(r'ADD_GROUP\("(?P[^"]+?)", "(?P[^"]*?)"\)'): ExtractType.GROUP, }