From 730bb2ee3e030b471b56d47ebc77da4aeea3186d Mon Sep 17 00:00:00 2001 From: Damien Picard Date: Mon, 2 Oct 2023 19:11:49 +0200 Subject: [PATCH] I18n: make new bones and bone collections' names translatable Newly created bones and bone collections get a default name. Like other types of data, these names should be translated if the user enabled the translation of new data in the preferences. This commit adds the appropriate `DATA_()` macro: - when creating a new armature; - when creating a new bone; - when creating a new bone collection through `ANIM_bonecoll_new()`; - when ensuring that a new bone collection has a unique name; - when renaming a bone collection; - in the bone collection tests, to check that new bones have the expected translated name. It also sets the default value of the bone name in the `ARMATURE_OT_bone_primitive_add()` operator to a null string instead of "Bone", so that the default name may be chosen while checking for unique names, since an empty string will default to the translation. Pull Request: https://projects.blender.org/blender/blender/pulls/113171 --- source/blender/animrig/CMakeLists.txt | 1 + source/blender/animrig/intern/bone_collections.cc | 8 +++++--- source/blender/animrig/intern/bone_collections_test.cc | 6 ++++-- source/blender/editors/armature/armature_add.cc | 8 +++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/source/blender/animrig/CMakeLists.txt b/source/blender/animrig/CMakeLists.txt index e819e73637c..637a2d35b45 100644 --- a/source/blender/animrig/CMakeLists.txt +++ b/source/blender/animrig/CMakeLists.txt @@ -7,6 +7,7 @@ set(INC intern ../blenkernel + ../blentranslation ../editors/include ) diff --git a/source/blender/animrig/intern/bone_collections.cc b/source/blender/animrig/intern/bone_collections.cc index f08c3ffc255..215a7c789b6 100644 --- a/source/blender/animrig/intern/bone_collections.cc +++ b/source/blender/animrig/intern/bone_collections.cc @@ -15,6 +15,8 @@ #include "BLI_string_utils.h" #include "BLI_utildefines.h" +#include "BLT_translation.h" + #include "DNA_armature_types.h" #include "BLI_math_bits.h" @@ -47,7 +49,7 @@ BoneCollection *ANIM_bonecoll_new(const char *name) { if (name == nullptr || name[0] == '\0') { /* Use a default name if no name was given. */ - name = bonecoll_default_name; + name = DATA_(bonecoll_default_name); } /* Note: the collection name may change after the collection is added to an @@ -112,7 +114,7 @@ static void bonecoll_ensure_name_unique(bArmature *armature, BoneCollection *bco { BLI_uniquename(&armature->collections, bcoll, - bonecoll_default_name, + DATA_(bonecoll_default_name), '.', offsetof(BoneCollection, name), sizeof(bcoll->name)); @@ -247,7 +249,7 @@ void ANIM_armature_bonecoll_name_set(bArmature *armature, BoneCollection *bcoll, if (name[0] == '\0') { /* Refuse to have nameless collections. The name of the active collection is stored in DNA, and * an empty string means 'no active collection'. */ - STRNCPY(bcoll->name, bonecoll_default_name); + STRNCPY(bcoll->name, DATA_(bonecoll_default_name)); } else { STRNCPY_UTF8(bcoll->name, name); diff --git a/source/blender/animrig/intern/bone_collections_test.cc b/source/blender/animrig/intern/bone_collections_test.cc index d250908a105..f55dc356d4a 100644 --- a/source/blender/animrig/intern/bone_collections_test.cc +++ b/source/blender/animrig/intern/bone_collections_test.cc @@ -4,6 +4,8 @@ #include "BLI_string.h" +#include "BLT_translation.h" + #include "ANIM_bone_collections.h" #include "testing/testing.h" @@ -24,13 +26,13 @@ TEST(ANIM_bone_collections, bonecoll_default_name) { { BoneCollection *bcoll = ANIM_bonecoll_new(""); - EXPECT_EQ("Bones", std::string(bcoll->name)); + EXPECT_EQ(DATA_("Bones"), std::string(bcoll->name)); ANIM_bonecoll_free(bcoll); } { BoneCollection *bcoll = ANIM_bonecoll_new(nullptr); - EXPECT_EQ("Bones", std::string(bcoll->name)); + EXPECT_EQ(DATA_("Bones"), std::string(bcoll->name)); ANIM_bonecoll_free(bcoll); } } diff --git a/source/blender/editors/armature/armature_add.cc b/source/blender/editors/armature/armature_add.cc index 5be2b1f493d..da2eba48157 100644 --- a/source/blender/editors/armature/armature_add.cc +++ b/source/blender/editors/armature/armature_add.cc @@ -22,6 +22,8 @@ #include "BLI_math_vector.h" #include "BLI_string_utils.h" +#include "BLT_translation.h" + #include "BKE_action.h" #include "BKE_armature.h" #include "BKE_constraint.h" @@ -95,7 +97,7 @@ EditBone *ED_armature_ebone_add_primitive(Object *obedit_arm, float length, bool ED_armature_edit_deselect_all(obedit_arm); /* Create a bone */ - bone = ED_armature_ebone_add(arm, "Bone"); + bone = ED_armature_ebone_add(arm, DATA_("Bone")); arm->act_edbone = bone; @@ -268,7 +270,7 @@ EditBone *add_points_bone(Object *obedit, float head[3], float tail[3]) { EditBone *ebo; - ebo = ED_armature_ebone_add(static_cast(obedit->data), "Bone"); + ebo = ED_armature_ebone_add(static_cast(obedit->data), DATA_("Bone")); copy_v3_v3(ebo->head, head); copy_v3_v3(ebo->tail, tail); @@ -1695,7 +1697,7 @@ void ARMATURE_OT_bone_primitive_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_string(ot->srna, "name", "Bone", MAXBONENAME, "Name", "Name of the newly created bone"); + RNA_def_string(ot->srna, "name", nullptr, MAXBONENAME, "Name", "Name of the newly created bone"); } /* ********************** Subdivide *******************************/