From f66049e9df5dfd4c1801d78e000b73a8d724a754 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 16 Nov 2021 19:18:38 +0200 Subject: [PATCH 36/36] sdl2: Use common sex module to get name of the sex See osdn #43229 Signed-off-by: Marko Lindqvist --- client/gui-sdl2/dialogs.c | 17 ++++++++++++----- common/sex.c | 19 +++++++++++++++++-- common/sex.h | 1 + translations/core/POTFILES.in | 1 + 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/client/gui-sdl2/dialogs.c b/client/gui-sdl2/dialogs.c index 59aad77510..1041a97a1a 100644 --- a/client/gui-sdl2/dialogs.c +++ b/client/gui-sdl2/dialogs.c @@ -41,6 +41,7 @@ #include "game.h" #include "government.h" #include "movement.h" +#include "sex.h" #include "unitlist.h" /* client */ @@ -2590,9 +2591,11 @@ static int change_sex_callback(struct widget *sex) struct nation_info *setup = (struct nation_info *)(nation_dlg->end_widget_list->data.ptr); if (setup->leader_sex) { - copy_chars_to_utf8_str(setup->change_sex->string_utf8, _("Female")); + copy_chars_to_utf8_str(setup->change_sex->string_utf8, + sex_name_translation(SEX_FEMALE)); } else { - copy_chars_to_utf8_str(setup->change_sex->string_utf8, _("Male")); + copy_chars_to_utf8_str(setup->change_sex->string_utf8, + sex_name_translation(SEX_MALE)); } setup->leader_sex = !setup->leader_sex; @@ -3012,9 +3015,11 @@ static void select_random_leader(Nation_type_id nation) setup->leader_sex = nation_leader_is_male(pleader); if (setup->leader_sex) { - copy_chars_to_utf8_str(setup->change_sex->string_utf8, _("Male")); + copy_chars_to_utf8_str(setup->change_sex->string_utf8, + sex_name_translation(SEX_MALE)); } else { - copy_chars_to_utf8_str(setup->change_sex->string_utf8, _("Female")); + copy_chars_to_utf8_str(setup->change_sex->string_utf8, + sex_name_translation(SEX_FEMALE)); } /* disable navigation buttons */ @@ -3265,7 +3270,9 @@ void popup_races_dialog(struct player *pplayer) setup->name_prev = pwidget; /* change sex button */ - pwidget = create_icon_button_from_chars(NULL, pwindow->dst, _("Male"), adj_font(14), 0); + pwidget = create_icon_button_from_chars(NULL, pwindow->dst, + sex_name_translation(SEX_MALE), + adj_font(14), 0); pwidget->action = change_sex_callback; pwidget->size.w = adj_size(100); pwidget->size.h = adj_size(22); diff --git a/common/sex.c b/common/sex.c index 5c0b103e86..60311a6971 100644 --- a/common/sex.c +++ b/common/sex.c @@ -16,6 +16,7 @@ #endif /* utility */ +#include "fcintl.h" #include "support.h" #include "sex.h" @@ -43,10 +44,24 @@ const char *sex_rule_name(int kind) { switch (kind) { case SEX_MALE: - return "Male"; + return N_("Male"); case SEX_FEMALE: - return "Female"; + return N_("Female"); } return NULL; } + +/************************************************************************//** + Return translated name of the sex. +****************************************************************************/ +const char *sex_name_translation(int kind) +{ + const char *rule_name = sex_rule_name(kind); + + if (rule_name == NULL) { + return NULL; + } + + return _(rule_name); +} diff --git a/common/sex.h b/common/sex.h index 278aed6ab1..fa5f156857 100644 --- a/common/sex.h +++ b/common/sex.h @@ -23,6 +23,7 @@ extern "C" { int sex_by_name(const char *name); const char *sex_rule_name(int kind); +const char *sex_name_translation(int kind); #ifdef __cplusplus } diff --git a/translations/core/POTFILES.in b/translations/core/POTFILES.in index fd57ec0c13..8826d6f81f 100644 --- a/translations/core/POTFILES.in +++ b/translations/core/POTFILES.in @@ -153,6 +153,7 @@ common/requirements.h common/research.c common/road.h common/server_settings.c +common/sex.c common/team.c common/tech.c common/tech.h -- 2.33.0