[Bf-blender-cvs] [dead26b5778] master: I18n: translate untitled file names

Damien Picard noreply at git.blender.org
Mon Sep 5 15:29:25 CEST 2022


Commit: dead26b5778b8bebd642884f11a254edd31c11bc
Author: Damien Picard
Date:   Mon Sep 5 15:25:34 2022 +0200
Branches: master
https://developer.blender.org/rBdead26b5778b8bebd642884f11a254edd31c11bc

I18n: translate untitled file names

When saving, the default file name is "untitled" regardless of
selected language. This can be translated, like many graphical
applications do.

This applies to:
- blend file
- alembic file
- collada file
- obj file
- usd file
- rendered image
- grease pencil export
- subtitles export
- other Python exports through ExportHelper

Reviewed By: mont29

Differential Revision: https://developer.blender.org/D15868

===================================================================

M	release/scripts/modules/bpy_extras/io_utils.py
M	source/blender/blenkernel/intern/image_save.cc
M	source/blender/editors/io/io_alembic.c
M	source/blender/editors/io/io_collada.c
M	source/blender/editors/io/io_gpencil_export.c
M	source/blender/editors/io/io_obj.c
M	source/blender/editors/io/io_usd.c
M	source/blender/editors/space_sequencer/sequencer_edit.c
M	source/blender/windowmanager/intern/wm_files.c

===================================================================

diff --git a/release/scripts/modules/bpy_extras/io_utils.py b/release/scripts/modules/bpy_extras/io_utils.py
index 0497d69162e..cc6aa6b9afa 100644
--- a/release/scripts/modules/bpy_extras/io_utils.py
+++ b/release/scripts/modules/bpy_extras/io_utils.py
@@ -21,7 +21,7 @@ from bpy.props import (
     EnumProperty,
     StringProperty,
 )
-
+from bpy.app.translations import pgettext_data as data_
 
 def _check_axis_conversion(op):
     if hasattr(op, "axis_forward") and hasattr(op, "axis_up"):
@@ -56,7 +56,7 @@ class ExportHelper:
         if not self.filepath:
             blend_filepath = context.blend_data.filepath
             if not blend_filepath:
-                blend_filepath = "untitled"
+                blend_filepath = data_("untitled")
             else:
                 blend_filepath = os.path.splitext(blend_filepath)[0]
 
diff --git a/source/blender/blenkernel/intern/image_save.cc b/source/blender/blenkernel/intern/image_save.cc
index 5ee1258c512..e65a94d5301 100644
--- a/source/blender/blenkernel/intern/image_save.cc
+++ b/source/blender/blenkernel/intern/image_save.cc
@@ -13,6 +13,8 @@
 #include "BLI_string.h"
 #include "BLI_vector.hh"
 
+#include "BLT_translation.h"
+
 #include "DNA_image_types.h"
 
 #include "MEM_guardedalloc.h"
@@ -173,7 +175,7 @@ bool BKE_image_save_options_init(ImageSaveOptions *opts,
           BLI_strncpy(opts->filepath, G.ima, sizeof(opts->filepath));
         }
         else {
-          BLI_strncpy(opts->filepath, "//untitled", sizeof(opts->filepath));
+          BLI_snprintf(opts->filepath, sizeof(opts->filepath), "//%s", DATA_("untitled"));
           BLI_path_abs(opts->filepath, BKE_main_blendfile_path(bmain));
         }
       }
diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c
index a7e906b8109..dd35279e0d6 100644
--- a/source/blender/editors/io/io_alembic.c
+++ b/source/blender/editors/io/io_alembic.c
@@ -80,7 +80,7 @@ static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent *
     char filepath[FILE_MAX];
 
     if (BKE_main_blendfile_path(bmain)[0] == '\0') {
-      BLI_strncpy(filepath, "untitled", sizeof(filepath));
+      BLI_strncpy(filepath, DATA_("untitled"), sizeof(filepath));
     }
     else {
       BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c
index c491e7a5815..6a5547021e4 100644
--- a/source/blender/editors/io/io_collada.c
+++ b/source/blender/editors/io/io_collada.c
@@ -43,7 +43,7 @@ static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent *
     const char *blendfile_path = BKE_main_blendfile_path(bmain);
 
     if (blendfile_path[0] == '\0') {
-      BLI_strncpy(filepath, "untitled", sizeof(filepath));
+      BLI_strncpy(filepath, DATA_("untitled"), sizeof(filepath));
     }
     else {
       BLI_strncpy(filepath, blendfile_path, sizeof(filepath));
diff --git a/source/blender/editors/io/io_gpencil_export.c b/source/blender/editors/io/io_gpencil_export.c
index 3f905dd7de0..7dfbf06f3c3 100644
--- a/source/blender/editors/io/io_gpencil_export.c
+++ b/source/blender/editors/io/io_gpencil_export.c
@@ -79,7 +79,7 @@ static void set_export_filepath(bContext *C, wmOperator *op, const char *extensi
     char filepath[FILE_MAX];
 
     if (BKE_main_blendfile_path(bmain)[0] == '\0') {
-      BLI_strncpy(filepath, "untitled", sizeof(filepath));
+      BLI_strncpy(filepath, DATA_("untitled"), sizeof(filepath));
     }
     else {
       BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index c151baf13ef..615c992ebff 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -63,7 +63,7 @@ static int wm_obj_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
     char filepath[FILE_MAX];
 
     if (BKE_main_blendfile_path(bmain)[0] == '\0') {
-      BLI_strncpy(filepath, "untitled", sizeof(filepath));
+      BLI_strncpy(filepath, DATA_("untitled"), sizeof(filepath));
     }
     else {
       BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index a59cdf60243..def7196d8ef 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -90,7 +90,7 @@ static int wm_usd_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
     const char *main_blendfile_path = BKE_main_blendfile_path(bmain);
 
     if (main_blendfile_path[0] == '\0') {
-      BLI_strncpy(filepath, "untitled", sizeof(filepath));
+      BLI_strncpy(filepath, DATA_("untitled"), sizeof(filepath));
     }
     else {
       BLI_strncpy(filepath, main_blendfile_path, sizeof(filepath));
diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c
index 7f23df4c94f..e37d254b16f 100644
--- a/source/blender/editors/space_sequencer/sequencer_edit.c
+++ b/source/blender/editors/space_sequencer/sequencer_edit.c
@@ -3093,7 +3093,7 @@ static int sequencer_export_subtitles_invoke(bContext *C,
     char filepath[FILE_MAX];
 
     if (BKE_main_blendfile_path(bmain)[0] == '\0') {
-      BLI_strncpy(filepath, "untitled", sizeof(filepath));
+      BLI_strncpy(filepath, DATA_("untitled"), sizeof(filepath));
     }
     else {
       BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index fb3da9dc7ec..13c1579d24b 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -3019,7 +3019,9 @@ void WM_OT_recover_auto_save(wmOperatorType *ot)
 static void wm_filepath_default(const Main *bmain, char *filepath)
 {
   if (bmain->filepath[0] == '\0') {
-    BLI_path_filename_ensure(filepath, FILE_MAX, "untitled.blend");
+    char filename_untitled[FILE_MAXFILE];
+    SNPRINTF(filename_untitled, "%s.blend", DATA_("untitled"));
+    BLI_path_filename_ensure(filepath, FILE_MAX, filename_untitled);
   }
 }
 
@@ -3652,7 +3654,7 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C,
     BLI_split_file_part(blendfile_path, filename, sizeof(filename));
   }
   else {
-    STRNCPY(filename, "untitled.blend");
+    SNPRINTF(filename, "%s.blend", DATA_("untitled"));
   }
   uiItemL(layout, filename, ICON_NONE);



More information about the Bf-blender-cvs mailing list