You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-13 13:31:48 +00:00
Improve editor property capitalization
* Captialize stop words when they are the last word. * Add stop words logic in `extract.py`.
This commit is contained in:
@@ -64,8 +64,8 @@ String EditorPropertyNameProcessor::_capitalize_name(const String &p_name) const
|
|||||||
|
|
||||||
Vector<String> parts = p_name.split("_", false);
|
Vector<String> parts = p_name.split("_", false);
|
||||||
for (int i = 0; i < parts.size(); i++) {
|
for (int i = 0; i < parts.size(); i++) {
|
||||||
// Articles/conjunctions/prepositions which should only be capitalized if first word.
|
// Articles/conjunctions/prepositions which should only be capitalized when not at beginning and end.
|
||||||
if (i != 0 && stop_words.find(parts[i]) != -1) {
|
if (i > 0 && i + 1 < parts.size() && stop_words.find(parts[i]) != -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
HashMap<String, String>::ConstIterator remap = capitalize_string_remaps.find(parts[i]);
|
HashMap<String, String>::ConstIterator remap = capitalize_string_remaps.find(parts[i]);
|
||||||
@@ -260,6 +260,8 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
|
|||||||
capitalize_string_remaps["yz"] = "YZ";
|
capitalize_string_remaps["yz"] = "YZ";
|
||||||
|
|
||||||
// Articles, conjunctions, prepositions.
|
// Articles, conjunctions, prepositions.
|
||||||
|
// The following initialization is parsed in `editor/translations/extract.py` with a regex.
|
||||||
|
// The word definition format should be kept synced with the regex.
|
||||||
stop_words = LocalVector<String>({
|
stop_words = LocalVector<String>({
|
||||||
"a",
|
"a",
|
||||||
"an",
|
"an",
|
||||||
|
|||||||
@@ -71,12 +71,25 @@ matches.sort()
|
|||||||
|
|
||||||
remaps = {}
|
remaps = {}
|
||||||
remap_re = re.compile(r'^\t*capitalize_string_remaps\["(?P<from>.+)"\] = (String::utf8\()?"(?P<to>.+)"')
|
remap_re = re.compile(r'^\t*capitalize_string_remaps\["(?P<from>.+)"\] = (String::utf8\()?"(?P<to>.+)"')
|
||||||
|
stop_words = set()
|
||||||
|
stop_words_re = re.compile(r'^\t*"(?P<word>.+)",')
|
||||||
|
is_inside_stop_words = False
|
||||||
with open("editor/editor_property_name_processor.cpp") as f:
|
with open("editor/editor_property_name_processor.cpp") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
|
if is_inside_stop_words:
|
||||||
|
m = stop_words_re.search(line)
|
||||||
|
if m:
|
||||||
|
stop_words.add(m.group("word"))
|
||||||
|
else:
|
||||||
|
is_inside_stop_words = False
|
||||||
|
else:
|
||||||
m = remap_re.search(line)
|
m = remap_re.search(line)
|
||||||
if m:
|
if m:
|
||||||
remaps[m.group("from")] = m.group("to")
|
remaps[m.group("from")] = m.group("to")
|
||||||
|
|
||||||
|
if not is_inside_stop_words and not stop_words:
|
||||||
|
is_inside_stop_words = "stop_words = " in line
|
||||||
|
|
||||||
|
|
||||||
main_po = """
|
main_po = """
|
||||||
# LANGUAGE translation of the Godot Engine editor.
|
# LANGUAGE translation of the Godot Engine editor.
|
||||||
@@ -147,9 +160,12 @@ capitalize_re = re.compile(r"(?<=\D)(?=\d)|(?<=\d)(?=\D([a-z]|\d))")
|
|||||||
def _process_editor_string(name):
|
def _process_editor_string(name):
|
||||||
# See EditorPropertyNameProcessor::process_string().
|
# See EditorPropertyNameProcessor::process_string().
|
||||||
capitalized_parts = []
|
capitalized_parts = []
|
||||||
for segment in name.split("_"):
|
parts = list(filter(bool, name.split("_"))) # Non-empty only.
|
||||||
if not segment:
|
for i, segment in enumerate(parts):
|
||||||
|
if i > 0 and i + 1 < len(parts) and segment in stop_words:
|
||||||
|
capitalized_parts.append(segment)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
remapped = remaps.get(segment)
|
remapped = remaps.get(segment)
|
||||||
if remapped:
|
if remapped:
|
||||||
capitalized_parts.append(remapped)
|
capitalized_parts.append(remapped)
|
||||||
|
|||||||
Reference in New Issue
Block a user