Skip to content

Commit

Permalink
Add position marker to some format strings (#34183)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Qrox authored and ZhilkinSerg committed Sep 23, 2019
1 parent 858ae21 commit fe55636
Show file tree
Hide file tree
Showing 30 changed files with 180 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
3 changes: 2 additions & 1 deletion src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
3 changes: 2 additions & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( "<npcname> load %i charge of %s in their %s.",
"<npcname> 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( "<npcname> load %1$i charge of %2$s in their %3$s.",
"<npcname> load %1$i charges of %2$s in their %3$s.", loadable ), loadable, it.tname(), bio->name );
mod_moves( -250 );
return true;
}
Expand Down
13 changes: 7 additions & 6 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ static item_location set_item_map_or_vehicle( const player &p, const tripoint &l
if( const cata::optional<vehicle_stack::iterator> 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", "<npcname> puts the %s on the %s." ),
pgettext( "item, furniture", "You put the %1$s on the %2$s." ),
pgettext( "item, furniture", "<npcname> puts the %1$s on the %2$s." ),
( *it )->tname(), vp->part().name() );

return item_location( vehicle_cursor( vp->vehicle(), vp->part_index() ), & **it );
Expand All @@ -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", "<npcname> puts the %s on the %s." ),
pgettext( "item, furniture", "You put the %1$s on the %2$s." ),
pgettext( "item, furniture", "<npcname> puts the %1$s on the %2$s." ),
newit.tname(), workbench.name() );
} else {
p.add_msg_player_or_npc(
Expand Down Expand Up @@ -1831,8 +1831,9 @@ ret_val<bool> player::can_disassemble( const item &obj, const inventory &inv ) c
return ret_val<bool>::make_failure( _( "You need %s." ),
item::nname( tool_required.type ) );
} else {
return ret_val<bool>::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<bool>::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 );
}
Expand Down
3 changes: 2 additions & 1 deletion src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand Down
16 changes: 10 additions & 6 deletions src/handle_liquid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::function<void()>> actions;

Expand Down
3 changes: 2 additions & 1 deletion src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>( 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() );
}

Expand Down
11 changes: 5 additions & 6 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down
39 changes: 29 additions & 10 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2867,7 +2867,8 @@ std::string item::info( std::vector<iteminfo> &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: " );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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<unsigned int> 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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -323,7 +324,8 @@ class item : public visitable<item>
*/
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<unsigned int> 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.
Expand Down
11 changes: 8 additions & 3 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!" ) );
}
Expand Down Expand Up @@ -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() ) {
Expand All @@ -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 ] ++;
}
Expand Down
Loading

0 comments on commit fe55636

Please sign in to comment.