From fe55636ed2c7392ef72a44fe06d027c8d43328ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jianxiang=20Wang=20=28=E7=8E=8B=E5=81=A5=E7=BF=94=29?= Date: Tue, 24 Sep 2019 00:36:45 +0800 Subject: [PATCH] Add position marker to some format strings (#34183) * Allow changing parameter position in cash card name translation * Add position marker to several format strings * Fix comment location and change another string * Fully allow changing parameter order in requirement format strings --- src/advanced_inv.cpp | 2 +- src/avatar.cpp | 3 ++- src/character.cpp | 3 ++- src/consumption.cpp | 10 +++++---- src/crafting.cpp | 13 +++++------ src/creature.cpp | 3 ++- src/game.cpp | 4 +++- src/game_inventory.cpp | 4 +++- src/handle_action.cpp | 5 +++-- src/handle_liquid.cpp | 16 ++++++++------ src/iexamine.cpp | 3 ++- src/inventory_ui.cpp | 11 +++++----- src/item.cpp | 39 ++++++++++++++++++++++++--------- src/item.h | 4 +++- src/iuse.cpp | 11 +++++++--- src/iuse_actor.cpp | 10 ++++++--- src/mattack_actors.cpp | 4 ++-- src/melee.cpp | 4 +++- src/monexamine.cpp | 4 +++- src/monmove.cpp | 10 ++++++--- src/monster.cpp | 10 ++++++--- src/npc.cpp | 3 ++- src/npctalk_funcs.cpp | 5 +++-- src/overmapbuffer.cpp | 12 +++++------ src/pickup.cpp | 11 ++++------ src/player.cpp | 20 ++++++++++------- src/requirements.cpp | 49 ++++++++++++++++++++++++++---------------- src/requirements.h | 6 +++--- src/vehicle_use.cpp | 3 ++- src/weather.cpp | 3 ++- 30 files changed, 180 insertions(+), 105 deletions(-) diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index 193199316e9f7..2ca74b14bacb8 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -1147,7 +1147,7 @@ void advanced_inventory::redraw_pane( side p ) const int max_page = ( pane.items.size() + itemsPerPage - 1 ) / itemsPerPage; if( active && max_page > 1 ) { const int page = pane.index / itemsPerPage; - mvwprintz( w, point( 2, 4 ), c_light_blue, _( "[<] page %d of %d [>]" ), page + 1, max_page ); + mvwprintz( w, point( 2, 4 ), c_light_blue, _( "[<] page %1$d of %2$d [>]" ), page + 1, max_page ); } if( active ) { diff --git a/src/avatar.cpp b/src/avatar.cpp index 81535b01da7ef..e68cd4f7413ac 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -484,7 +484,8 @@ bool avatar::read( int inventory_position, const bool continuous ) }; menu.title = !skill ? string_format( _( "Reading %s" ), it.type_name() ) : - string_format( _( "Reading %s (can train %s from %d to %d)" ), it.type_name(), + //~ %1$s: book name, %2$s: skill name, %3$d and %4$d: skill levels + string_format( _( "Reading %1$s (can train %2$s from %3$d to %4$d)" ), it.type_name(), skill_name, type->req, type->level ); if( skill ) { diff --git a/src/character.cpp b/src/character.cpp index f6dafc85670a4..a76154e5183ad 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -1068,7 +1068,8 @@ int Character::i_add_to_container( const item &it, const bool unloading ) auto &contained_ammo = container.contents.front(); if( contained_ammo.charges < container.ammo_capacity() ) { const int diff = container.ammo_capacity() - contained_ammo.charges; - add_msg( _( "You put the %s in your %s." ), it.tname(), container.tname() ); + //~ %1$s: item name, %2$s: container name + add_msg( pgettext( "container", "You put the %1$s in your %2$s." ), it.tname(), container.tname() ); if( diff > charges ) { contained_ammo.charges += charges; return 0; diff --git a/src/consumption.cpp b/src/consumption.cpp index c434780cf269f..c37526fcf2e00 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1331,10 +1331,12 @@ bool player::fuel_bionic_with( item &it ) set_value( it.typeId(), loaded_charge );// type and amount of fuel update_fuel_storage( it.typeId() ); add_msg_player_or_npc( m_info, - ngettext( "You load %i charge of %s in your %s.", - "You load %i charges of %s in your %s.", loadable ), - ngettext( " load %i charge of %s in their %s.", - " load %i charges of %s in their %s.", loadable ), loadable, it.tname(), bio->name ); + //~ %1$i: charge number, %2$s: item name, %3$s: bionics name + ngettext( "You load %1$i charge of %2$s in your %3$s.", + "You load %1$i charges of %2$s in your %3$s.", loadable ), + //~ %1$i: charge number, %2$s: item name, %3$s: bionics name + ngettext( " load %1$i charge of %2$s in their %3$s.", + " load %1$i charges of %2$s in their %3$s.", loadable ), loadable, it.tname(), bio->name ); mod_moves( -250 ); return true; } diff --git a/src/crafting.cpp b/src/crafting.cpp index b233738fd02c5..8f78b67ab0530 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -697,8 +697,8 @@ static item_location set_item_map_or_vehicle( const player &p, const tripoint &l if( const cata::optional it = vp->vehicle().add_item( vp->part_index(), newit ) ) { p.add_msg_player_or_npc( - pgettext( "item, furniture", "You put the %s on the %s." ), - pgettext( "item, furniture", " puts the %s on the %s." ), + pgettext( "item, furniture", "You put the %1$s on the %2$s." ), + pgettext( "item, furniture", " puts the %1$s on the %2$s." ), ( *it )->tname(), vp->part().name() ); return item_location( vehicle_cursor( vp->vehicle(), vp->part_index() ), & **it ); @@ -716,8 +716,8 @@ static item_location set_item_map_or_vehicle( const player &p, const tripoint &l if( g->m.has_furn( loc ) ) { const furn_t &workbench = g->m.furn( loc ).obj(); p.add_msg_player_or_npc( - pgettext( "item, furniture", "You put the %s on the %s." ), - pgettext( "item, furniture", " puts the %s on the %s." ), + pgettext( "item, furniture", "You put the %1$s on the %2$s." ), + pgettext( "item, furniture", " puts the %1$s on the %2$s." ), newit.tname(), workbench.name() ); } else { p.add_msg_player_or_npc( @@ -1831,8 +1831,9 @@ ret_val player::can_disassemble( const item &obj, const inventory &inv ) c return ret_val::make_failure( _( "You need %s." ), item::nname( tool_required.type ) ); } else { - return ret_val::make_failure( ngettext( "You need a %s with %d charge.", - "You need a %s with %d charges.", tool_required.count ), + //~ %1$s: tool name, %2$d: needed charges + return ret_val::make_failure( ngettext( "You need a %1$s with %2$d charge.", + "You need a %1$s with %2$d charges.", tool_required.count ), item::nname( tool_required.type ), tool_required.count ); } diff --git a/src/creature.cpp b/src/creature.cpp index 61dd14c806fe6..1bf9cc6417577 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -795,7 +795,8 @@ void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack SCT.removeCreatureHP(); } - add_msg( m_good, _( "You hit %s for %d damage." ), + //~ %1$s: creature name, %2$d: damage value + add_msg( m_good, _( "You hit %1$s for %2$d damage." ), disp_name(), dealt_dam.total_damage() ); } else if( u_see_this ) { //~ 1$ - shooter, 2$ - target diff --git a/src/game.cpp b/src/game.cpp index a590449262b7e..ead23c022749d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -8641,7 +8641,9 @@ void game::wield( item_location &loc ) // Need to do this here because holster_actor::use() checks if/where the item is worn item &target = *loc.get_item(); if( target.get_use( "holster" ) && !target.contents.empty() ) { - if( query_yn( _( "Draw %s from %s?" ), target.get_contained().tname(), target.tname() ) ) { + //~ %1$s: weapon name, %2$s: holster name + if( query_yn( pgettext( "holster", "Draw %1$s from %2$s?" ), target.get_contained().tname(), + target.tname() ) ) { u.invoke_item( &target ); return; } diff --git a/src/game_inventory.cpp b/src/game_inventory.cpp index 3a6df324ff334..766a33c14a959 100644 --- a/src/game_inventory.cpp +++ b/src/game_inventory.cpp @@ -909,7 +909,9 @@ class read_inventory_preset: public pickup_inventory_preset if( book.skill ) { const SkillLevel &skill = p.get_skill_level_object( book.skill ); if( skill.can_train() ) { - return string_format( _( "%s to %d (%d)" ), book.skill->name(), book.level, skill.level() ); + //~ %1$s: book skill name, %2$d: book skill level, %3$d: player skill level + return string_format( pgettext( "skill", "%1$s to %2$d (%3$d)" ), book.skill->name(), book.level, + skill.level() ); } } return std::string(); diff --git a/src/handle_action.cpp b/src/handle_action.cpp index c9a5e217ff5ab..7883aff293dfd 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -1271,8 +1271,9 @@ static void fire() for( auto &w : u.worn ) { if( w.type->can_use( "holster" ) && !w.has_flag( "NO_QUICKDRAW" ) && !w.contents.empty() && w.contents.front().is_gun() ) { - // draw (first) gun contained in holster - options.push_back( string_format( _( "%s from %s (%d)" ), + //~ draw (first) gun contained in holster + //~ %1$s: weapon name, %2$s: container name, %3$d: remaining ammo count + options.push_back( string_format( pgettext( "holster", "%1$s from %2$s (%3$d)" ), w.contents.front().tname(), w.type_name(), w.contents.front().ammo_remaining() ) ); diff --git a/src/handle_liquid.cpp b/src/handle_liquid.cpp index 745e15b326870..aff3ff0ccf183 100644 --- a/src/handle_liquid.cpp +++ b/src/handle_liquid.cpp @@ -160,16 +160,20 @@ static bool get_liquid_target( item &liquid, item *const source, const int radiu const std::string liquid_name = liquid.display_name( liquid.charges ); if( source_pos != nullptr ) { - menu.text = string_format( _( "What to do with the %s from %s?" ), liquid_name, + //~ %1$s: liquid name, %2$s: terrain name + menu.text = string_format( pgettext( "liquid", "What to do with the %1$s from %2$s?" ), liquid_name, g->m.name( *source_pos ) ); } else if( source_veh != nullptr ) { - menu.text = string_format( _( "What to do with the %s from the %s?" ), liquid_name, - source_veh->name ); + //~ %1$s: liquid name, %2$s: vehicle name + menu.text = string_format( pgettext( "liquid", "What to do with the %1$s from %2$s?" ), liquid_name, + source_veh->disp_name() ); } else if( source_mon != nullptr ) { - menu.text = string_format( _( "What to do with the %s from the %s?" ), liquid_name, - source_mon->get_name() ); + //~ %1$s: liquid name, %2$s: monster name + menu.text = string_format( pgettext( "liquid", "What to do with the %1$s from the %2$s?" ), + liquid_name, source_mon->get_name() ); } else { - menu.text = string_format( _( "What to do with the %s?" ), liquid_name ); + //~ %s: liquid name + menu.text = string_format( pgettext( "liquid", "What to do with the %s?" ), liquid_name ); } std::vector> actions; diff --git a/src/iexamine.cpp b/src/iexamine.cpp index 0acc16638f201..c8a02085b6e86 100644 --- a/src/iexamine.cpp +++ b/src/iexamine.cpp @@ -2117,7 +2117,8 @@ void iexamine::fertilize_plant( player &p, const tripoint &tile, const itype_id g->m.furn_set( tile, old_furn ); p.mod_moves( -to_moves( 10_seconds ) ); - add_msg( m_info, _( "You fertilize the %s with the %s." ), seed->get_plant_name(), + //~ %1$s: plant name, %2$s: fertilizer name + add_msg( m_info, _( "You fertilize the %1$s with the %2$s." ), seed->get_plant_name(), planted.front().tname() ); } diff --git a/src/inventory_ui.cpp b/src/inventory_ui.cpp index bfb0d5275b613..2cbca38e45660 100644 --- a/src/inventory_ui.cpp +++ b/src/inventory_ui.cpp @@ -91,18 +91,17 @@ class selection_column_preset : public inventory_selector_preset const item_location &item = entry.any_item(); if( entry.chosen_count > 0 && entry.chosen_count < available_count ) { - res << string_format( _( "%d of %d" ), entry.chosen_count, available_count ) << ' '; + //~ %1$d: chosen count, %2$d: available count + res << string_format( pgettext( "count", "%1$d of %2$d" ), entry.chosen_count, + available_count ) << ' '; } else if( available_count != 1 ) { res << available_count << ' '; } if( item->is_money() ) { assert( available_count == entry.get_stack_size() ); if( entry.chosen_count > 0 && entry.chosen_count < available_count ) { - res << string_format( - //~ In the following string, the %s is the amount of money on the selected cards as passed by the display money function, out of the total amount of money on the cards, which is specified by the format_money function") - _( "%s of %s" ), - item->display_money( available_count, entry.get_selected_charges() ), - format_money( entry.get_total_charges() ) ); + res << item->display_money( available_count, entry.get_total_charges(), + entry.get_selected_charges() ); } else { res << item->display_money( available_count, entry.get_total_charges() ); } diff --git a/src/item.cpp b/src/item.cpp index 421c41d228dd1..ddc7e52f5f475 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -2867,7 +2867,8 @@ std::string item::info( std::vector &info, const iteminfo_query *parts insert_separation_line(); std::string ntext; if( item_note_type != item_vars.end() ) { - ntext += string_format( _( "%1$s on the %2$s is: " ), + //~ %1$s: gerund (e.g. carved), %2$s: item name + ntext += string_format( pgettext( "carving", "%1$s on the %2$s is: " ), item_note_type->second.c_str(), tname() ); } else { ntext += _( "Note: " ); @@ -3442,16 +3443,19 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t const item &contents_item = contents.front(); if( contents_item.made_of( LIQUID ) || contents_item.is_food() ) { const unsigned contents_count = contents_item.charges > 1 ? contents_item.charges : quantity; - maintext = string_format( pgettext( "item name", "%s of %s" ), label( quantity ), + //~ %1$s: item name, %2$s: content liquid, food, or drink name + maintext = string_format( pgettext( "item name", "%1$s of %2$s" ), label( quantity ), contents_item.tname( contents_count, with_prefix ) ); } else { - maintext = string_format( pgettext( "item name", "%s with %s" ), label( quantity ), + //~ %1$s: item name, %2$s: non-liquid, non-food, non-drink content item name + maintext = string_format( pgettext( "item name", "%1$s with %2$s" ), label( quantity ), contents_item.tname( quantity, with_prefix ) ); } } else if( !contents.empty() ) { maintext = string_format( npgettext( "item name", - "%s with %zd item", - "%s with %zd items", contents.size() ), + //~ %1$s: item name, %2$zd: content size + "%1$s with %2$zd item", + "%1$s with %2$zd items", contents.size() ), label( quantity ), contents.size() ); } else { maintext = label( quantity ); @@ -3591,11 +3595,25 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t } } -std::string item::display_money( unsigned int quantity, unsigned int amount ) const +std::string item::display_money( unsigned int quantity, unsigned int total, + cata::optional selected ) const { - //~ This is a string to display the total amount of money in a stack of cash cards. The strings are: %s is the display name of cash cards. The following bracketed $%.2f is the amount of money on the stack of cards in dollars, to two decimal points. (e.g. "cash cards ($15.35)") - return string_format( pgettext( "cash card and total money", "%s %s" ), tname( quantity ), - format_money( amount ) ); + if( selected ) { + //~ This is a string to display the selected and total amount of money in a stack of cash cards. + //~ %1$s is the display name of cash cards. + //~ %2$s is the total amount of money. + //~ %3$s is the selected amount of money. + //~ Example: "cash cards $15.35 of $20.48" + return string_format( pgettext( "cash card and money", "%1$s %3$s of %2$s" ), tname( quantity ), + format_money( total ), format_money( *selected ) ); + } else { + //~ This is a string to display the total amount of money in a stack of cash cards. + //~ %1$s is the display name of cash cards. + //~ %2$s is the total amount of money on the cash cards. + //~ Example: "cash cards $20.48" + return string_format( pgettext( "cash card and money", "%1$s %2$s" ), tname( quantity ), + format_money( total ) ); + } } std::string item::display_name( unsigned int quantity ) const @@ -6797,7 +6815,8 @@ bool item::reload( player &u, item_location loc, int qty ) } else if( !magazine_integral() ) { // if we already have a magazine loaded prompt to eject it if( magazine_current() ) { - std::string prompt = string_format( _( "Eject %s from %s?" ), + //~ %1$s: magazine name, %2$s: weapon name + std::string prompt = string_format( pgettext( "magazine", "Eject %1$s from %2$s?" ), magazine_current()->tname(), tname() ); // eject magazine to player inventory and try to dispose of it from there diff --git a/src/item.h b/src/item.h index 0cc8b0d91cdee..1eef227e5f7a6 100644 --- a/src/item.h +++ b/src/item.h @@ -22,6 +22,7 @@ #include "flat_set.h" #include "io_tags.h" #include "item_location.h" +#include "optional.h" #include "relic.h" #include "requirements.h" #include "safe_reference.h" @@ -323,7 +324,8 @@ class item : public visitable */ std::string tname( unsigned int quantity = 1, bool with_prefix = true, unsigned int truncate = 0 ) const; - std::string display_money( unsigned int quantity, unsigned int amount ) const; + std::string display_money( unsigned int quantity, unsigned int total, + cata::optional selected = cata::nullopt ) const; /** * Returns the item name and the charges or contained charges (if the item can have * charges at all). Calls @ref tname with given quantity and with_prefix being true. diff --git a/src/iuse.cpp b/src/iuse.cpp index 1c9b440d00a17..168f1ac9adead 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -4163,7 +4163,9 @@ int iuse::rpgdie( player *you, item *die, bool, const tripoint & ) die->set_var( "die_num_sides", sides ); } const int roll = rng( 1, num_sides ); - you->add_msg_if_player( _( "You roll a %d on your %d sided %s" ), roll, num_sides, die->tname() ); + //~ %1$d: roll number, %2$d: side number of a die, %3$s: die item name + you->add_msg_if_player( pgettext( "dice", "You roll a %1$d on your %2$d sided %3$s" ), roll, + num_sides, die->tname() ); if( roll == num_sides ) { add_msg( m_good, _( "Critical!" ) ); } @@ -7111,7 +7113,8 @@ static object_names_collection enumerate_objects_around_point( const tripoint &p ret_obj.vehicles[ veh_name ] ++; } else if( point == point_around_figure ) { // point is center - description_part_on_figure = string_format( _( "%1$s from %2$s" ), + //~ %1$s: vehicle part name, %2$s: vehicle name + description_part_on_figure = string_format( pgettext( "vehicle part", "%1$s from %2$s" ), veh_part_pos.part_displayed()->part().name(), veh_name ); if( ret_obj.vehicles.find( veh_name ) != ret_obj.vehicles.end() && local_vehicles_recorded.find( veh_hash ) != local_vehicles_recorded.end() ) { @@ -7128,7 +7131,9 @@ static object_names_collection enumerate_objects_around_point( const tripoint &p std::string item_name = colorized_item_name( item ); item_name = trap_name + item_name + field_desc; if( point == point_around_figure && create_figure_desc ) { - description_terrain_on_figure = string_format( _( "%1$s with a %2$s" ), ter_desc, item_name ); + //~ %1$s: terrain description, %2$s: item name + description_terrain_on_figure = string_format( pgettext( "terrain and item", "%1$s with a %2$s" ), + ter_desc, item_name ); } else { ret_obj.items[ item_name ] ++; } diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index 124f9454ad9f3..45afe1e11d0a4 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -1648,7 +1648,8 @@ bool inscribe_actor::item_inscription( item &cut ) const const bool hasnote = cut.has_var( carving ); std::string messageprefix = string_format( hasnote ? _( "(To delete, input one '.')\n" ) : "" ) + - string_format( _( "%1$s on the %2$s is: " ), + //~ %1$s: gerund (e.g. carved), %2$s: item name + string_format( pgettext( "carving", "%1$s on the %2$s is: " ), _( gerund ), cut.type_name() ); string_input_popup popup; @@ -2405,7 +2406,8 @@ void cast_spell_actor::load( JsonObject &obj ) void cast_spell_actor::info( const item &, std::vector &dump ) const { - const std::string message = string_format( _( "This item casts %s at level %i." ), + //~ %1$s: spell name, %2$i: spell level + const std::string message = string_format( _( "This item casts %1$s at level %2$i." ), item_spell->name, spell_level ); dump.emplace_back( "DESCRIPTION", message ); if( no_fail ) { @@ -3724,7 +3726,9 @@ hp_part heal_actor::use_healing_item( player &healer, player &patient, item &it, } else { // Player healing NPC // TODO: Remove this hack, allow using activities on NPCs - const std::string menu_header = string_format( _( "Select a body part of %s for %s:" ), + const std::string menu_header = string_format( pgettext( "healing", + //~ %1$s: patient name, %2$s: healing item name + "Select a body part of %1$s for %2$s:" ), patient.disp_name(), it.tname() ); healed = pick_part_to_heal( healer, patient, menu_header, limb_power, head_bonus, torso_bonus, diff --git a/src/mattack_actors.cpp b/src/mattack_actors.cpp index b7364b25f933c..a1583fa963a23 100644 --- a/src/mattack_actors.cpp +++ b/src/mattack_actors.cpp @@ -155,8 +155,8 @@ void mon_spellcasting_actor::load_internal( JsonObject &obj, const std::string & optional( obj, was_loaded, "spell_level", spell_level, 0 ); translation monster_message; optional( obj, was_loaded, "monster_message", monster_message, - //~ translator " cast on !" - to_translation( "%s casts %s at %s!" ) ); + //~ " cast on !" + to_translation( "%1$s casts %2$s at %3$s!" ) ); spell_data = spell( spell_id( sp_id ), monster_message ); for( int i = 0; i <= spell_level; i++ ) { spell_data.gain_level(); diff --git a/src/melee.cpp b/src/melee.cpp index a156ab9a3c499..0e96f2feac8d5 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -2195,8 +2195,10 @@ void player::disarm( npc &target ) my_roll += dice( 3, get_skill_level( skill_unarmed ) ); if( my_roll >= their_roll ) { + //~ %s: weapon name add_msg( _( "You grab at %s and pull with all your force!" ), it.tname() ); - add_msg( _( "You forcefully take %s from %s!" ), it.tname(), target.name ); + //~ %1$s: weapon name, %2$s: NPC name + add_msg( _( "You forcefully take %1$s from %2$s!" ), it.tname(), target.name ); // wield() will deduce our moves, consider to deduce more/less moves for balance item rem_it = target.i_rem( &it ); wield( rem_it ); diff --git a/src/monexamine.cpp b/src/monexamine.cpp index fe26a6aad6e77..00f02e47bdcaf 100644 --- a/src/monexamine.cpp +++ b/src/monexamine.cpp @@ -613,7 +613,9 @@ void monexamine::remove_armor( monster &z ) found_armor = true; it.erase_var( "pet_armor" ); g->m.add_item_or_charges( z.pos(), it ); - add_msg( m_info, "You remove the %1$s from %2$s.", it.tname( 1 ), pet_name ); + //~ %1$s: armor name, %2$s: pet name + add_msg( m_info, pgettext( "pet armor", "You remove the %1$s from %2$s." ), it.tname( 1 ), + pet_name ); z.inv.erase( z.inv.begin() + pos ); g->u.moves -= 200; break; diff --git a/src/monmove.cpp b/src/monmove.cpp index 8c93691845761..7475d386f2f62 100644 --- a/src/monmove.cpp +++ b/src/monmove.cpp @@ -1393,12 +1393,16 @@ bool monster::move_to( const tripoint &p, bool force, const float stagger_adjust g->m.tername( pos() ) ); } } else if( was_water && !will_be_water && g->u.sees( p ) ) { - //Use more dramatic messages for swimming monsters - add_msg( m_warning, _( "A %1$s %2$s from the %3$s!" ), name(), + // Use more dramatic messages for swimming monsters + //~ Message when a monster emerges from water + //~ %1$s: monster name, %2$s: leaps/emerges, %3$s: terrain name + add_msg( m_warning, pgettext( "monster movement", "A %1$s %2$s from the %3$s!" ), name(), has_flag( MF_SWIMS ) || has_flag( MF_AQUATIC ) ? _( "leaps" ) : _( "emerges" ), g->m.tername( pos() ) ); } else if( !was_water && will_be_water && g->u.sees( p ) ) { - add_msg( m_warning, _( "A %1$s %2$s into the %3$s!" ), name(), + //~ Message when a monster enters water + //~ %1$s: monster name, %2$s: dives/sinks, %3$s: terrain name + add_msg( m_warning, pgettext( "monster movement", "A %1$s %2$s into the %3$s!" ), name(), has_flag( MF_SWIMS ) || has_flag( MF_AQUATIC ) ? _( "dives" ) : _( "sinks" ), g->m.tername( p ) ); } diff --git a/src/monster.cpp b/src/monster.cpp index 01d6a9c22ed98..5bf7056d9b5fc 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -1302,18 +1302,22 @@ void monster::melee_attack( Creature &target, float accuracy ) body_part_name_accusative( bp_hit ) ); } else if( target.is_npc() ) { if( has_effect( effect_ridden ) && has_flag( MF_RIDEABLE_MECH ) && pos() == g->u.pos() ) { - add_msg( m_good, _( "Your %s hits %s for %d damage!" ), name(), target.disp_name(), total_dealt ); + //~ %1$s: name of your mount, %2$s: target NPC name, %3$d: damage value + add_msg( m_good, _( "Your %1$s hits %2$s for %3$d damage!" ), name(), target.disp_name(), + total_dealt ); } else { - //~ 1$s is attacker name, 2$s is target name, 3$s is bodypart name in accusative. + //~ %1$s: attacker name, %2$s: target NPC name, %3$s: bodypart name in accusative add_msg( _( "The %1$s hits %2$s %3$s." ), name(), target.disp_name( true ), body_part_name_accusative( bp_hit ) ); } } else { if( has_effect( effect_ridden ) && has_flag( MF_RIDEABLE_MECH ) && pos() == g->u.pos() ) { - add_msg( m_good, _( "Your %s hits %s for %d damage!" ), get_name(), target.disp_name(), + //~ %1$s: name of your mount, %2$s: target creature name, %3$d: damage value + add_msg( m_good, _( "Your %1$s hits %2$s for %3$d damage!" ), get_name(), target.disp_name(), total_dealt ); } else { + //~ %1$s: attacker name, %2$s: target creature name add_msg( _( "The %1$s hits %2$s!" ), name(), target.disp_name() ); } } diff --git a/src/npc.cpp b/src/npc.cpp index 89f4fb2a32b60..7d1d997fe43df 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -919,7 +919,8 @@ void npc::stow_item( item &it ) } for( auto &e : worn ) { if( e.can_holster( it ) ) { - add_msg_if_npc( m_info, _( " puts away the %s in the %s." ), weapon.tname(), + //~ %1$s: weapon name, %2$s: holster name + add_msg_if_npc( m_info, _( " puts away the %1$s in the %2$s." ), weapon.tname(), e.tname() ); auto ptr = dynamic_cast( e.type->get_use( "holster" )->get_actor_ptr() ); ptr->store( *this, e, it ); diff --git a/src/npctalk_funcs.cpp b/src/npctalk_funcs.cpp index a2ce02a1b03df..74c6739600fc9 100644 --- a/src/npctalk_funcs.cpp +++ b/src/npctalk_funcs.cpp @@ -307,8 +307,9 @@ void talk_function::goto_location( npc &p ) camps.push_back( temp_camp ); } for( auto iter : camps ) { - selection_menu.addentry( i++, true, MENU_AUTOASSIGN, _( "%s at (%d, %d)" ), iter->camp_name(), - iter->camp_omt_pos().x, iter->camp_omt_pos().y ); + //~ %1$s: camp name, %2$d and %3$d: coordinates + selection_menu.addentry( i++, true, MENU_AUTOASSIGN, pgettext( "camp", "%1$s at (%2$d, %3$d)" ), + iter->camp_name(), iter->camp_omt_pos().x, iter->camp_omt_pos().y ); } selection_menu.addentry( i++, true, MENU_AUTOASSIGN, _( "My current location" ) ); selection_menu.addentry( i++, true, MENU_AUTOASSIGN, _( "Cancel" ) ); diff --git a/src/overmapbuffer.cpp b/src/overmapbuffer.cpp index e8efb055cac2d..781c4b4176d32 100644 --- a/src/overmapbuffer.cpp +++ b/src/overmapbuffer.cpp @@ -1259,29 +1259,29 @@ std::string overmapbuffer::get_description_at( const tripoint &where ) const int sm_dist = closest_cref.distance; //~ First parameter is a terrain name, second parameter is a direction, and third parameter is a city name. - std::string format_string = _( "%1$s %2$s from %3$s" ); + std::string format_string = pgettext( "terrain description", "%1$s %2$s from %3$s" ); if( sm_dist <= 3 * sm_size / 4 ) { if( sm_size >= 16 ) { // The city is big enough to be split in districts. if( sm_dist <= sm_size / 4 ) { //~ First parameter is a terrain name, second parameter is a direction, and third parameter is a city name. - format_string = _( "%1$s in central %3$s" ); + format_string = pgettext( "terrain description", "%1$s in central %3$s" ); } else { //~ First parameter is a terrain name, second parameter is a direction, and third parameter is a city name. - format_string = _( "%1$s in %2$s %3$s" ); + format_string = pgettext( "terrain description", "%1$s in %2$s %3$s" ); } } else { //~ First parameter is a terrain name, second parameter is a direction, and third parameter is a city name. - format_string = _( "%1$s in %3$s" ); + format_string = pgettext( "terrain description", "%1$s in %3$s" ); } } else if( sm_dist <= sm_size ) { if( sm_size >= 8 ) { // The city is big enough to have outskirts. //~ First parameter is a terrain name, second parameter is a direction, and third parameter is a city name. - format_string = _( "%1$s on the %2$s outskirts of %3$s" ); + format_string = pgettext( "terrain description", "%1$s on the %2$s outskirts of %3$s" ); } else { //~ First parameter is a terrain name, second parameter is a direction, and third parameter is a city name. - format_string = _( "%1$s in %3$s" ); + format_string = pgettext( "terrain description", "%1$s in %3$s" ); } } diff --git a/src/pickup.cpp b/src/pickup.cpp index 1a86504edd19b..c4ae616fc2df3 100644 --- a/src/pickup.cpp +++ b/src/pickup.cpp @@ -874,14 +874,11 @@ void Pickup::pick_up( const tripoint &p, int min, from_where get_items_from ) charges += ( *it )->charges; } if( stealing ) { - //~ %s %s of %s ""!20 Cash Cards of $200" - ! added if stealing. - item_name = string_format( _( "%s %s of %s" ), stolen, - stacked_here[true_it].front()->display_money( getitem[true_it].count, charges ), - format_money( charges_total ) ); + item_name = string_format( "%s %s", stolen, + stacked_here[true_it].front()->display_money( getitem[true_it].count, charges_total, charges ) ); } else { - item_name = string_format( _( "%s of %s" ), - stacked_here[true_it].front()->display_money( getitem[true_it].count, charges ), - format_money( charges_total ) ); + item_name = stacked_here[true_it].front()->display_money( getitem[true_it].count, charges_total, + charges ); } } } else { diff --git a/src/player.cpp b/src/player.cpp index a72ceb714fc36..9f85bf0d294af 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -3510,7 +3510,7 @@ int player::impact( const int force, const tripoint &p ) if( total_dealt > 0 && is_player() ) { // "You slam against the dirt" is fine - add_msg( m_bad, _( "You are slammed against %s for %d damage." ), + add_msg( m_bad, _( "You are slammed against %1$s for %2$d damage." ), target_name, total_dealt ); } else if( is_player() && shock_absorbers ) { add_msg( m_bad, _( "You are slammed against %s!" ), @@ -7265,11 +7265,12 @@ item::reload_option player::select_ammo( const item &base, if( e.ammo->is_magazine() && e.ammo->ammo_data() ) { if( e.ammo->ammo_current() == "battery" ) { // This battery ammo is not a real object that can be recovered but pseudo-object that represents charge - //~ magazine with ammo count - return string_format( _( "%s (%d)" ), e.ammo->type_name(), e.ammo->ammo_remaining() ); + //~ battery storage (charges) + return string_format( pgettext( "magazine", "%1$s (%2$d)" ), e.ammo->type_name(), + e.ammo->ammo_remaining() ); } else { //~ magazine with ammo (count) - return string_format( _( "%s with %s (%d)" ), e.ammo->type_name(), + return string_format( pgettext( "magazine", "%1$s with %2$s (%3$d)" ), e.ammo->type_name(), e.ammo->ammo_data()->nname( e.ammo->ammo_remaining() ), e.ammo->ammo_remaining() ); } } else if( e.ammo->is_watertight_container() || @@ -7737,7 +7738,9 @@ bool player::wield( item &target ) // Query whether to draw an item from a holster when attempting to wield the holster if( target.get_use( "holster" ) && !target.contents.empty() ) { - if( query_yn( _( "Draw %s from %s?" ), target.get_contained().tname(), target.tname() ) ) { + //~ %1$s: weapon name, %2$s: holster name + if( query_yn( pgettext( "holster", "Draw %1$s from %2$s?" ), target.get_contained().tname(), + target.tname() ) ) { invoke_item( &target ); return false; } @@ -11719,9 +11722,10 @@ bool player::crush_frozen_liquid( item_location loc ) if( u.has_quality( quality_id( "HAMMER" ) ) ) { item hammering_item = u.item_with_best_of_quality( quality_id( "HAMMER" ) ); - if( query_yn( _( "Do you want to crush up %s with your %s?\n%s" ), loc.get_item()->display_name(), - hammering_item.tname(), - colorize( _( "Be wary of fragile items nearby!" ), c_red ) ) ) { + //~ %1$s: item to be crushed, %2$s: hammer name + if( query_yn( _( "Do you want to crush up %1$s with your %2$s?\n" + "Be wary of fragile items nearby!" ), + loc.get_item()->display_name(), hammering_item.tname() ) ) { //Risk smashing tile with hammering tool, risk is lower with higher dex, damage lower with lower strength if( one_in( 1 + u.dex_cur / 4 ) ) { diff --git a/src/requirements.cpp b/src/requirements.cpp index d7a29b4f610a9..827c77b96aa39 100644 --- a/src/requirements.cpp +++ b/src/requirements.cpp @@ -95,10 +95,11 @@ bool string_id::is_valid() const return quality_factory.is_valid( *this ); } -std::string quality_requirement::to_string( int ) const +std::string quality_requirement::to_string( const int, const int ) const { - return string_format( ngettext( "%d tool with %s of %d or more.", - "%d tools with %s of %d or more.", count ), + //~ %1$d: tool count, %2$s: quality requirement name, %3$d: quality level requirement + return string_format( ngettext( "%1$d tool with %2$s of %3$d or more.", + "%1$d tools with %2$s of %3$d or more.", count ), count, type.obj().name, level ); } @@ -107,26 +108,43 @@ bool tool_comp::by_charges() const return count > 0; } -std::string tool_comp::to_string( int batch ) const +std::string tool_comp::to_string( const int batch, const int ) const { if( by_charges() ) { - //~ ( charges) - return string_format( ngettext( "%s (%d charge)", "%s (%d charges)", count * batch ), + //~ %1$s: tool name, %2$d: charge requirement + return string_format( npgettext( "requirement", "%1$s (%2$d charge)", "%1$s (%2$d charges)", + count * batch ), item::nname( type ), count * batch ); } else { return item::nname( type, abs( count ) ); } } -std::string item_comp::to_string( int batch ) const +std::string item_comp::to_string( const int batch, const int avail ) const { const int c = std::abs( count ) * batch; const auto type_ptr = item::find_type( type ); if( type_ptr->count_by_charges() ) { - return string_format( "%s (%d)", type_ptr->nname( 1 ), c ); + if( avail > 0 ) { + //~ %1$s: item name, %2$d: charge requirement, %3%d: available charges + return string_format( npgettext( "requirement", "%1$s (%2$d of %3$d)", "%1$s (%2$d of %3$d)", c ), + type_ptr->nname( 1 ), c, avail ); + } else { + //~ %1$s: item name, %2$d: charge requirement + return string_format( npgettext( "requirement", "%1$s (%2$d)", "%1$s (%2$d)", c ), + type_ptr->nname( 1 ), c ); + } + } else { + if( avail > 0 ) { + //~ %1$s: item name, %2$d: required count, %3%d: available count + return string_format( npgettext( "requirement", "%2$d %1$s of %3$d", "%2$d %1$s of %3$d", c ), + type_ptr->nname( c ), c, avail ); + } else { + //~ %1$s: item name, %2$d: required count + return string_format( npgettext( "requirement", "%2$d %1$s", "%2$d %1$s", c ), + type_ptr->nname( c ), c ); + } } - //~ - return string_format( ngettext( "%d %s", "%d %s", c ), c, type_ptr->nname( c ) ); } void quality_requirement::load( JsonArray &jsarr ) @@ -487,21 +505,16 @@ std::vector requirement_data::get_folded_list( int width, for( const T &component : comp_list ) { nc_color color = component.get_color( has_one, crafting_inv, filter, batch ); const std::string color_tag = get_tag_from_color( color ); - std::string text = component.to_string( batch ); + int qty = 0; if( component.get_component_type() == COMPONENT_ITEM ) { const itype_id item_id = static_cast( component.type ); - int qty; if( item::count_by_charges( item_id ) ) { qty = crafting_inv.charges_of( item_id, INT_MAX, filter ); } else { qty = crafting_inv.amount_of( item_id, false, INT_MAX, filter ); } - if( qty > 0 ) { - text = item::count_by_charges( item_id ) ? - string_format( _( "%s (%d of %ld)" ), item::nname( item_id ), component.count * batch, qty ) : - string_format( _( "%s of %ld" ), text, qty ); - } } + const std::string text = component.to_string( batch, qty ); if( std::find( buffer_has.begin(), buffer_has.end(), text + color_tag ) != buffer_has.end() ) { continue; @@ -516,7 +529,7 @@ std::vector requirement_data::get_folded_list( int width, } std::sort( list_as_string.begin(), list_as_string.end() ); - const std::string separator = colorize( std::string( " " ) + _( "OR" ) + " ", c_white ); + const std::string separator = colorize( _( " OR " ), c_white ); const std::string unfolded = join( list_as_string, separator ); std::vector folded = foldstring( unfolded, width - 2 ); diff --git a/src/requirements.h b/src/requirements.h index 748f98409d62e..7b563420dbc05 100644 --- a/src/requirements.h +++ b/src/requirements.h @@ -77,7 +77,7 @@ struct tool_comp : public component { void load( JsonArray &ja ); bool has( const inventory &crafting_inv, const std::function &filter, int batch = 1, std::function visitor = std::function() ) const; - std::string to_string( int batch = 1 ) const; + std::string to_string( int batch = 1, int avail = 0 ) const; nc_color get_color( bool has_one, const inventory &crafting_inv, const std::function &filter, int batch = 1 ) const; bool by_charges() const; @@ -93,7 +93,7 @@ struct item_comp : public component { void load( JsonArray &ja ); bool has( const inventory &crafting_inv, const std::function &filter, int batch = 1, std::function visitor = std::function() ) const; - std::string to_string( int batch = 1 ) const; + std::string to_string( int batch = 1, int avail = 0 ) const; nc_color get_color( bool has_one, const inventory &crafting_inv, const std::function &filter, int batch = 1 ) const; component_type get_component_type() const { @@ -115,7 +115,7 @@ struct quality_requirement { void load( JsonArray &jsarr ); bool has( const inventory &crafting_inv, const std::function &filter, int = 0, std::function visitor = std::function() ) const; - std::string to_string( int = 0 ) const; + std::string to_string( int batch = 1, int avail = 0 ) const; void check_consistency( const std::string &display_name ) const; nc_color get_color( bool has_one, const inventory &crafting_inv, const std::function &filter, int = 0 ) const; diff --git a/src/vehicle_use.cpp b/src/vehicle_use.cpp index 8a3d8abdd729b..a60e6fd00f735 100644 --- a/src/vehicle_use.cpp +++ b/src/vehicle_use.cpp @@ -1573,7 +1573,8 @@ void vehicle::use_harness( int part, const tripoint &pos ) m.add_effect( effect_harnessed, 1_turns, num_bp, true ); m.setpos( pos ); - add_msg( m_info, _( "You harness your %s to the %s." ), m.get_name(), name ); + //~ %1$s: monster name, %2$s: vehicle name + add_msg( m_info, _( "You harness your %1$s to %2$s." ), m.get_name(), disp_name() ); if( m.has_effect( effect_tied ) ) { add_msg( m_info, _( "You untie your %s." ), m.get_name() ); m.remove_effect( effect_tied ); diff --git a/src/weather.cpp b/src/weather.cpp index 6685edc1c35b0..890b9d6d22b0e 100644 --- a/src/weather.cpp +++ b/src/weather.cpp @@ -594,7 +594,8 @@ std::string weather_forecast( const point &abs_sm_pos ) const std::string city_name = cref ? cref.city->name : std::string( _( "middle of nowhere" ) ); // Current time weather_report << string_format( - _( "The current time is %s Eastern Standard Time. At %s in %s, it was %s. The temperature was %s. " ), + //~ %1$s: time of day, %2$s: hour of day, %3$s: city name, %4$s: weather name, %5$s: temperature value + _( "The current time is %1$s Eastern Standard Time. At %2$s in %3$s, it was %4$s. The temperature was %5$s. " ), to_string_time_of_day( calendar::turn ), print_time_just_hour( calendar::turn ), city_name, weather::name( g->weather.weather ), print_temperature( g->weather.temperature )