Skip to content

Commit ed2828a

Browse files
authored
Merge pull request #83201 from RenechCDDA/fix_some_UI_translations
Fix some issues with extracting/showing translations
2 parents 34d12bc + 44bd99f commit ed2828a

16 files changed

+100
-70
lines changed

src/basecamp.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ void basecamp::handle_takeover_by( faction_id new_owner, bool violent_takeover )
886886
camp_workers.clear();
887887

888888
add_msg_debug( debugmode::DF_CAMPS, "Camp %s owned by %s is being taken over by %s!",
889-
name, fac()->name, new_owner->name );
889+
name, fac()->id.c_str(), new_owner->id.c_str() );
890890

891891
if( !violent_takeover ) {
892892
set_owner( new_owner );
@@ -913,7 +913,8 @@ void basecamp::handle_takeover_by( faction_id new_owner, bool violent_takeover )
913913
if( checked_camp->get_owner() == get_owner() ) {
914914
add_msg_debug( debugmode::DF_CAMPS,
915915
"Camp %s at %s is owned by %s, adding it to plunder calculations.",
916-
checked_camp->camp_name(), checked_camp->camp_omt_pos().to_string_writable(), get_owner()->name );
916+
checked_camp->camp_name(), checked_camp->camp_omt_pos().to_string_writable(),
917+
get_owner()->id.c_str() );
917918
num_of_owned_camps++;
918919
}
919920
}
@@ -933,7 +934,7 @@ void basecamp::handle_takeover_by( faction_id new_owner, bool violent_takeover )
933934
camp_food_supply( taken_from_camp );
934935
add_msg_debug( debugmode::DF_CAMPS,
935936
"Food supplies of %s plundered by %d kilocalories! Total food supply reduced to %d kilocalories after losing %.1f%% of their camps.",
936-
fac()->name, captured_with_camp.kcal(), fac()->food_supply().kcal(),
937+
fac()->id.c_str(), captured_with_camp.kcal(), fac()->food_supply().kcal(),
937938
1.0 / static_cast<double>( num_of_owned_camps ) * 100.0 );
938939
set_owner( new_owner );
939940
int previous_days_of_food = camp_food_supply_days( MODERATE_EXERCISE );
@@ -943,7 +944,7 @@ void basecamp::handle_takeover_by( faction_id new_owner, bool violent_takeover )
943944
fac()->add_to_food_supply( added );
944945
add_msg_debug( debugmode::DF_CAMPS,
945946
"Food supply of new owner %s has increased to %d kilocalories due to takeover of camp %s!",
946-
fac()->name, new_owner->food_supply().kcal(), name );
947+
fac()->id.c_str(), new_owner->food_supply().kcal(), name );
947948
if( new_owner == get_player_character().get_faction()->id ) {
948949
popup( _( "Through your looting of %s you found %d days worth of food and other resources." ),
949950
name, camp_food_supply_days( MODERATE_EXERCISE ) - previous_days_of_food );

src/calendar.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "options.h"
1616
#include "rng.h"
1717
#include "string_formatter.h"
18+
#include "translation.h"
1819
#include "translations.h"
1920
#include "units.h"
2021
#include "units_utility.h"
@@ -907,13 +908,13 @@ std::pair<month, int> month_and_day( time_point turn )
907908

908909
std::string to_string( month m )
909910
{
910-
static std::array<std::string, 12> months = {
911-
translate_marker_context( "month", "Jan" ), translate_marker_context( "month", "Feb" ),
912-
translate_marker_context( "month", "Mar" ), translate_marker_context( "month", "Apr" ),
913-
translate_marker_context( "month", "May" ), translate_marker_context( "month", "Jun" ),
914-
translate_marker_context( "month", "Jul" ), translate_marker_context( "month", "Aug" ),
915-
translate_marker_context( "month", "Sep" ), translate_marker_context( "month", "Oct" ),
916-
translate_marker_context( "month", "Nov" ), translate_marker_context( "month", "Dec" )
911+
static std::array<translation, 12> months = {
912+
to_translation( "month", "Jan" ), to_translation( "month", "Feb" ),
913+
to_translation( "month", "Mar" ), to_translation( "month", "Apr" ),
914+
to_translation( "month", "May" ), to_translation( "month", "Jun" ),
915+
to_translation( "month", "Jul" ), to_translation( "month", "Aug" ),
916+
to_translation( "month", "Sep" ), to_translation( "month", "Oct" ),
917+
to_translation( "month", "Nov" ), to_translation( "month", "Dec" )
917918
};
918919

919920
static_assert( static_cast<month>( 0 ) == month::JANUARY, "month enum out of phase" );
@@ -922,7 +923,7 @@ std::string to_string( month m )
922923
return _( "Cataclysm" );
923924
}
924925

925-
return _( months[static_cast<int>( m )] );
926+
return months[static_cast<int>( m )].translated();
926927
}
927928

928929
std::string get_diary_time_since_str( const time_duration &turn_diff, time_accuracy acc,

src/debug_menu.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,7 +2356,7 @@ static faction *select_faction()
23562356
uilist factionlist;
23572357
int facnum = 0;
23582358
for( const faction *faction : factions ) {
2359-
factionlist.addentry( facnum++, true, MENU_AUTOASSIGN, "%s", faction->name.c_str() );
2359+
factionlist.addentry( facnum++, true, MENU_AUTOASSIGN, "%s", faction->get_name() );
23602360
}
23612361

23622362
factionlist.query();
@@ -2903,7 +2903,7 @@ static void faction_edit_menu()
29032903
uilist nmenu;
29042904

29052905
std::stringstream data;
2906-
data << fac->name << std::endl;
2906+
data << fac->get_name() << std::endl;
29072907
data << fac->describe() << std::endl;
29082908
data << string_format( _( "Id: %s" ), fac->id.c_str() ) << std::endl;
29092909
data << string_format( _( "Wealth: %d" ), fac->wealth ) << " | "
@@ -4449,7 +4449,7 @@ void debug()
44494449
std::cout << std::to_string( count ) << " Faction_id key in factions map = " << elem.first.str() <<
44504450
std::endl;
44514451
std::cout << std::to_string( count ) << " Faction name associated with this id is " <<
4452-
elem.second.name << std::endl;
4452+
elem.second.get_name() << std::endl;
44534453
std::cout << std::to_string( count ) << " the id of that faction object is " << elem.second.id.str()
44544454
<< std::endl;
44554455
count++;

src/display.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ std::pair<std::string, nc_color> display::faction_text( const Character &u )
835835
if( owner->limited_area_claim && u.pos_abs_omt() != actual_camp->camp_omt_pos() ) {
836836
return std::pair( display_name, display_color );
837837
}
838-
display_name = owner->name;
838+
display_name = owner->get_name();
839839
// TODO: Make this magic number into a constant
840840
if( owner->likes_u < -10 ) {
841841
display_color = c_red;
@@ -954,9 +954,8 @@ std::pair<std::string, nc_color> display::vehicle_cruise_text_color( const Chara
954954
if( veh ) {
955955
const double target = convert_velocity( veh->cruise_velocity, VU_VEHICLE );
956956
const double current = convert_velocity( veh->velocity, VU_VEHICLE );
957-
const std::string units = get_option<std::string> ( "USE_METRIC_SPEEDS" );
958957
vel_text = string_format( "%s < %s %s", three_digit_display( target ),
959-
three_digit_display( current ), units );
958+
three_digit_display( current ), velocity_units( VU_VEHICLE ) );
960959

961960
const float strain = veh->strain( here );
962961
if( strain <= 0 ) {

src/faction.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ void faction_template::reset()
9696
npc_factions::all_templates.clear();
9797
}
9898

99+
std::string faction_template::get_name() const
100+
{
101+
return _( name );
102+
}
103+
104+
void faction_template::set_name( std::string new_name )
105+
{
106+
name = std::move( new_name );
107+
}
108+
99109
void faction_template::load_relations( const JsonObject &jsobj )
100110
{
101111
for( const JsonMember fac : jsobj.get_object( "relations" ) ) {
@@ -536,7 +546,7 @@ faction *faction_manager::add_new_faction( const std::string &name_new, const fa
536546
for( const faction_template &fac_temp : npc_factions::all_templates ) {
537547
if( template_id == fac_temp.id ) {
538548
faction fac( fac_temp );
539-
fac.name = name_new;
549+
fac.set_name( name_new );
540550
fac.id = id_new;
541551
factions[fac.id] = fac;
542552
return &factions[fac.id];
@@ -559,7 +569,7 @@ faction *faction_manager::get( const faction_id &id, const bool complain )
559569
elem.second.price_rules = fac_temp.price_rules;
560570
elem.second.lone_wolf_faction = fac_temp.lone_wolf_faction;
561571
elem.second.limited_area_claim = fac_temp.limited_area_claim;
562-
elem.second.name = fac_temp.name;
572+
elem.second.set_name( fac_temp.get_name() );
563573
elem.second.desc = fac_temp.desc;
564574
elem.second.mon_faction = fac_temp.mon_faction;
565575
elem.second.epilogue_data = fac_temp.epilogue_data;
@@ -994,7 +1004,7 @@ void faction_manager::display() const
9941004
const std::string no_fac = _( "You don't know of any factions." );
9951005
if( active_vec_size > 0 ) {
9961006
draw_list( std::function( [&valfac]( size_t i ) {
997-
return _( valfac[i]->name );
1007+
return valfac[i]->get_name();
9981008
} ) );
9991009
if( cur_fac ) {
10001010
cur_fac->faction_display( w_missions, 31 );

src/faction.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ class faction_template
123123
private:
124124
explicit faction_template( const JsonObject &jsobj );
125125

126-
127126
public:
128127
static void load( const JsonObject &jsobj );
129128
static void check_consistency();
@@ -141,7 +140,16 @@ class faction_template
141140
// debug access to food supply
142141
cata::list<std::pair<time_point, nutrients>> &debug_food_supply();
143142

143+
// Returns (hopefully) translated version of the faction's name.
144+
std::string get_name() const;
145+
// TODO: Move to faction constructor?
146+
void set_name( std::string new_name );
147+
148+
protected:
149+
// TODO: Shouldn't this be a translation object...
144150
std::string name;
151+
152+
public:
145153
int likes_u;
146154
int respects_u;
147155
int trusts_u; // Determines which item groups are available for trading
@@ -154,6 +162,7 @@ class faction_template
154162
// Sorted list of nutrients and when they expire
155163
// The time_point == 0 mod 1_days, and calendar::turn_zero is non-perishable food
156164
cata::list<std::pair<time_point, nutrients>> _food_supply; //Total nutritional value held
165+
157166
public:
158167
bool consumes_food; //Whether this faction actually draws down the food_supply when eating from it
159168
int wealth; //Total trade currency

src/game.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,7 +3000,7 @@ void game::display_faction_epilogues()
30003000
point( std::max( 0, ( TERMX - FULL_SCREEN_WIDTH ) / 2 ),
30013001
std::max( 0, ( TERMY - FULL_SCREEN_HEIGHT ) / 2 ) ) );
30023002
};
3003-
scrollable_text( new_win, elem.second.name,
3003+
scrollable_text( new_win, elem.second.get_name(),
30043004
std::accumulate( epilogue.begin() + 1, epilogue.end(), epilogue.front(),
30053005
[]( std::string lhs, const std::string & rhs ) -> std::string {
30063006
return std::move( lhs ) + "\n" + rhs;
@@ -5605,7 +5605,7 @@ bool game::warn_player_maybe_anger_local_faction( bool really_bad_offense,
56055605
// Else there's a camp, and we're doing something we're not supposed to! Time to warn the player.
56065606
if( !query_yn(
56075607
_( "You're in the territory of %s, they probably won't appreciate your actions. Continue anyway?" ),
5608-
actual_camp->get_owner()->name ) ) {
5608+
actual_camp->get_owner()->get_name() ) ) {
56095609
return false;
56105610
} else {
56115611
faction *owner_fac_pointer = g->faction_manager_ptr->get( actual_camp->get_owner() );

src/iexamine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,7 @@ void iexamine::bulletin_board( Character &you, const tripoint_bub_ms &examp )
22022202
temp_camp->camp_name() ) ) {
22032203
bool plunder = query_yn(
22042204
_( "Take whatever you can find from the stores? This may anger %s and their allies." ),
2205-
temp_camp->get_owner()->name );
2205+
temp_camp->get_owner()->get_name() );
22062206
temp_camp->handle_takeover_by( you.get_faction()->id, plunder );
22072207
return;
22082208
}

src/item.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ std::string item::get_old_owner_name() const
10601060
debugmsg( "item::get_owner_name() item %s has no valid nor null faction id", tname() );
10611061
return "no owner";
10621062
}
1063-
return g->faction_manager_ptr->get( get_old_owner() )->name;
1063+
return g->faction_manager_ptr->get( get_old_owner() )->get_name();
10641064
}
10651065

10661066
std::string item::get_owner_name() const
@@ -1069,7 +1069,7 @@ std::string item::get_owner_name() const
10691069
debugmsg( "item::get_owner_name() item %s has no valid nor null faction id ", tname() );
10701070
return "no owner";
10711071
}
1072-
return g->faction_manager_ptr->get( get_owner() )->name;
1072+
return g->faction_manager_ptr->get( get_owner() )->get_name();
10731073
}
10741074

10751075
void item::set_owner( const faction_id &new_owner )

src/item_info.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void item::basic_info( std::vector<iteminfo> &info, const iteminfo_query *parts,
283283
}
284284
if( parts->test( iteminfo_parts::BASE_OWNER ) && !owner.is_null() ) {
285285
info.emplace_back( "BASE", string_format( _( "Owner: %s" ),
286-
_( get_owner_name() ) ) );
286+
get_owner_name() ) );
287287
}
288288
if( parts->test( iteminfo_parts::BASE_CATEGORY ) ) {
289289
info.emplace_back( "BASE", _( "Category: " ),
@@ -394,7 +394,7 @@ void item::debug_info( std::vector<iteminfo> &info, const iteminfo_query *parts,
394394
typeId().str() ) );
395395
if( !old_owner.is_null() ) {
396396
info.emplace_back( "BASE", string_format( _( "Old owner: %s" ),
397-
_( get_old_owner_name() ) ) );
397+
get_old_owner_name() ) );
398398
}
399399
info.emplace_back( "BASE", _( "age (hours): " ), "", iteminfo::lower_is_better,
400400
to_hours<int>( age() ) );
@@ -1733,14 +1733,19 @@ void item::armor_protection_info( std::vector<iteminfo> &info, const iteminfo_qu
17331733
bool display_median = percent_best < 50 && percent_worst < 50;
17341734

17351735
std::string protection_table;
1736+
const std::string worst_chance_string = string_format( _( "<bad>%d%%</bad> chance" ),
1737+
percent_worst );
1738+
const std::string median_chance = _( "<color_c_yellow>Median</color> chance" );
1739+
const std::string best_chance_string = string_format( _( "<good>%d%%</good> chance" ),
1740+
percent_best );
17361741
if( display_median ) {
17371742
protection_table +=
1738-
string_format( "<bold>%s</bold>;<bad>%d%%</bad> chance;<color_c_yellow>Median</color> chance;<good>%d%%</good> chance\n",
1739-
_( "Protection" ), percent_worst, percent_best );
1743+
string_format( "<bold>%s</bold>;%s;%s;%s\n",
1744+
_( "Protection" ), worst_chance_string, median_chance, best_chance_string );
17401745
} else if( percent_worst > 0 ) {
17411746
protection_table +=
1742-
string_format( "<bold>%s</bold>;<bad>%d%%</bad> chance;<good>%d%%</good> chance\n",
1743-
_( "Protection" ), percent_worst, percent_best );
1747+
string_format( "<bold>%s</bold>;%s;%s\n",
1748+
_( "Protection" ), worst_chance_string, best_chance_string );
17441749
} else {
17451750
protection_table += string_format( "<bold>%s</bold>\n", _( "Protection" ) );
17461751
}
@@ -2715,7 +2720,7 @@ void item::tool_info( std::vector<iteminfo> &info, const iteminfo_query *parts,
27152720
std::string &eport = type->tool->e_port;
27162721
if( !eport.empty() ) {
27172722
std::string compat;
2718-
compat += _( "* This device has electronic port type: " + colorize( eport, c_light_green ) );
2723+
compat += _( "* This device has electronic port type: " ) + colorize( _( eport ), c_light_green ) ;
27192724
std::vector<std::string> &eport_banned = type->tool->e_ports_banned;
27202725
if( !eport_banned.empty() ) {
27212726
compat += _( "\n* This device does not support transfer to e-port types: " );

0 commit comments

Comments
 (0)