Skip to content

Commit e5f9f4d

Browse files
committed
Merge pull request #110618 from timothyqiu/editor-translations-h-cpp-split
Editor: Generate translation data in separate cpp files
2 parents 38d8059 + c93f555 commit e5f9f4d

File tree

2 files changed

+33
-37
lines changed

2 files changed

+33
-37
lines changed

editor/SCsub

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,23 @@ if env.editor_build:
5656
# ratio (20% for the editor UI, 10% for the class reference).
5757
# Generated with `make include-list` for each resource.
5858

59-
# Editor translations
60-
env.CommandNoCache(
61-
"#editor/translations/editor_translations.gen.h",
62-
Glob("#editor/translations/editor/*"),
63-
env.Run(editor_builders.make_translations_header),
64-
)
65-
66-
# Property translations
67-
env.CommandNoCache(
68-
"#editor/translations/property_translations.gen.h",
69-
Glob("#editor/translations/properties/*"),
70-
env.Run(editor_builders.make_translations_header),
71-
)
72-
73-
# Documentation translations
74-
env.CommandNoCache(
75-
"#editor/translations/doc_translations.gen.h",
76-
Glob("#doc/translations/*"),
77-
env.Run(editor_builders.make_translations_header),
78-
)
79-
80-
# Extractable translations
81-
env.CommandNoCache(
82-
"#editor/translations/extractable_translations.gen.h",
83-
Glob("#editor/translations/extractable/*"),
84-
env.Run(editor_builders.make_translations_header),
85-
)
59+
translation_targets = {
60+
"#editor/translations/editor_translations.gen.cpp": Glob("#editor/translations/editor/*"),
61+
"#editor/translations/property_translations.gen.cpp": Glob("#editor/translations/properties/*"),
62+
"#editor/translations/doc_translations.gen.cpp": Glob("#doc/translations/*"),
63+
"#editor/translations/extractable_translations.gen.cpp": Glob("#editor/translations/extractable/*"),
64+
}
65+
for target_cpp, sources in translation_targets.items():
66+
target_h = os.path.splitext(target_cpp)[0] + ".h"
67+
env.CommandNoCache(
68+
[target_h, target_cpp],
69+
sources,
70+
env.Run(editor_builders.make_translations),
71+
)
8672

8773
env.add_source_files(env.editor_sources, "*.cpp")
8874
env.add_source_files(env.editor_sources, gen_exporters)
75+
env.add_source_files(env.editor_sources, translation_targets.keys())
8976

9077
SConscript("animation/SCsub")
9178
SConscript("asset_library/SCsub")

editor/editor_builders.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,18 @@ def make_doc_header(target, source, env):
6868
""")
6969

7070

71-
def make_translations_header(target, source, env):
72-
category = os.path.basename(str(target[0])).split("_")[0]
71+
def make_translations(target, source, env):
72+
target_h, target_cpp = str(target[0]), str(target[1])
73+
74+
category = os.path.basename(target_h).split("_")[0]
7375
sorted_paths = sorted([src.abspath for src in source], key=lambda path: os.path.splitext(os.path.basename(path))[0])
7476

7577
xl_names = []
7678
msgfmt = env.Detect("msgfmt")
7779
if not msgfmt:
7880
methods.print_warning("msgfmt not found, using .po files instead of .mo")
7981

80-
with methods.generated_wrapper(str(target[0])) as file:
82+
with methods.generated_wrapper(target_cpp) as file:
8183
for path in sorted_paths:
8284
name = os.path.splitext(os.path.basename(path))[0]
8385
# msgfmt erases non-translated messages, so avoid using it if exporting the POT.
@@ -120,14 +122,9 @@ def make_translations_header(target, source, env):
120122
xl_names.append([name, len(buffer), decomp_size])
121123

122124
file.write(f"""\
123-
struct {category.capitalize()}TranslationList {{
124-
const char* lang;
125-
int comp_size;
126-
int uncomp_size;
127-
const unsigned char* data;
128-
}};
125+
#include "{target_h}"
129126
130-
inline constexpr {category.capitalize()}TranslationList _{category}_translations[] = {{
127+
const {category.capitalize()}TranslationList _{category}_translations[] = {{
131128
""")
132129

133130
for x in xl_names:
@@ -136,4 +133,16 @@ def make_translations_header(target, source, env):
136133
file.write("""\
137134
{ nullptr, 0, 0, nullptr },
138135
};
136+
""")
137+
138+
with methods.generated_wrapper(target_h) as file:
139+
file.write(f"""\
140+
struct {category.capitalize()}TranslationList {{
141+
const char* lang;
142+
int comp_size;
143+
int uncomp_size;
144+
const unsigned char* data;
145+
}};
146+
147+
extern const {category.capitalize()}TranslationList _{category}_translations[];
139148
""")

0 commit comments

Comments
 (0)