diff --git a/editor/SCsub b/editor/SCsub index 442d0a3b753..f4d30b68b14 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -104,6 +104,7 @@ if env.editor_build: # Extractable translations tlist = glob.glob(env.Dir("#editor/translations/extractable").abspath + "/*.po") + tlist.extend(glob.glob(env.Dir("#editor/translations/extractable").abspath + "/extractable.pot")) env.Depends("#editor/extractable_translations.gen.h", tlist) env.CommandNoCache( "#editor/extractable_translations.gen.h", diff --git a/editor/editor_builders.py b/editor/editor_builders.py index 68595047feb..a25f4949c41 100644 --- a/editor/editor_builders.py +++ b/editor/editor_builders.py @@ -61,7 +61,9 @@ def make_translations_header(target, source, env, category): xl_names = [] for i in range(len(sorted_paths)): - if msgfmt_available: + name = os.path.splitext(os.path.basename(sorted_paths[i]))[0] + # msgfmt erases non-translated messages, so avoid using it if exporting the POT. + if msgfmt_available and name != category: mo_path = os.path.join(tempfile.gettempdir(), uuid.uuid4().hex + ".mo") cmd = "msgfmt " + sorted_paths[i] + " --no-hash -o " + mo_path try: @@ -79,7 +81,7 @@ def make_translations_header(target, source, env, category): try: os.remove(mo_path) except OSError as e: - # Do not fail the entire build if it cannot delete a temporary file + # Do not fail the entire build if it cannot delete a temporary file. print( "WARNING: Could not delete temporary .mo file: path=%r; [%s] %s" % (mo_path, e.__class__.__name__, e) @@ -88,11 +90,13 @@ def make_translations_header(target, source, env, category): with open(sorted_paths[i], "rb") as f: buf = f.read() + if name == category: + name = "source" + decomp_size = len(buf) # Use maximum zlib compression level to further reduce file size # (at the cost of initial build times). buf = zlib.compress(buf, zlib.Z_BEST_COMPRESSION) - name = os.path.splitext(os.path.basename(sorted_paths[i]))[0] g.write("static const unsigned char _{}_translation_{}_compressed[] = {{\n".format(category, name)) for j in range(len(buf)): diff --git a/editor/editor_translation.cpp b/editor/editor_translation.cpp index 302a81669d1..194d78326d5 100644 --- a/editor/editor_translation.cpp +++ b/editor/editor_translation.cpp @@ -160,20 +160,22 @@ List get_extractable_message_list() { ExtractableTranslationList *etl = _extractable_translations; List msgids; while (etl->data) { - Vector data; - data.resize(etl->uncomp_size); - int ret = Compression::decompress(data.ptrw(), etl->uncomp_size, etl->data, etl->comp_size, Compression::MODE_DEFLATE); - ERR_FAIL_COND_V_MSG(ret == -1, msgids, "Compressed file is corrupt."); + if (!strcmp(etl->lang, "source")) { + Vector data; + data.resize(etl->uncomp_size); + int ret = Compression::decompress(data.ptrw(), etl->uncomp_size, etl->data, etl->comp_size, Compression::MODE_DEFLATE); + ERR_FAIL_COND_V_MSG(ret == -1, msgids, "Compressed file is corrupt."); - Ref fa; - fa.instantiate(); - fa->open_custom(data.ptr(), data.size()); + Ref fa; + fa.instantiate(); + fa->open_custom(data.ptr(), data.size()); - Ref tr = TranslationLoaderPO::load_translation(fa); + Ref tr = TranslationLoaderPO::load_translation(fa); - if (tr.is_valid()) { - tr->get_message_list(&msgids); - break; + if (tr.is_valid()) { + tr->get_message_list(&msgids); + break; + } } etl++;