Skip to content

Commit

Permalink
Fix more translation and translation updating issues (#33433)
Browse files Browse the repository at this point in the history
* Fix translation update - skill names

* Fix translation update - bionic names/descriptions

* Remove some explicit `translated` calls

* Fix translation update - recipe category names

* Fix translation update - terrain bash sound descriptions

* Fix translation - trap-vehicle collision sound description

* Convert .pot file line endings to Unix on Windows

* Suppress warning when nothing translatable is found in objects copying from other objects

* Update translation documentation

* Mark a string for translation

* Fix translation update - vehicle part names

* Fix translation update - text snippets

* Update translation documentation

* Use no_translation for debug text
  • Loading branch information
Qrox authored and ZhilkinSerg committed Aug 25, 2019
1 parent 2783181 commit 60e0ca9
Show file tree
Hide file tree
Showing 27 changed files with 136 additions and 104 deletions.
5 changes: 5 additions & 0 deletions doc/TRANSLATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ new syntax "name" would be a `dict`, which may break unmigrated script.
| Mutation names/descriptions
| NPC class names/descriptions
| Tool quality names
| Skill names/descriptions
| Bionic names/descriptions
| Terrain bash sound descriptions
| Trap-vehicle collision sound descriptions
| Vehicle part names/descriptions

### Recommendations

Expand Down
11 changes: 8 additions & 3 deletions lang/extract_json_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def warning_supressed(filename):
"TOOLMOD",
"TOOL_ARMOR",
"tool_quality",
"trap",
"tutorial_messages",
"VAR_VEH_PART",
"vehicle",
Expand Down Expand Up @@ -569,6 +568,11 @@ def extract_talk_topic(item):
for r in item["responses"]:
extract_talk_response(r, outfile)

def extract_trap(item):
outfile = get_outfile("trap")
writestr(outfile, item["name"])
if "vehicle_data" in item and "sound" in item["vehicle_data"]:
writestr(outfile, item["vehicle_data"]["sound"], comment="Trap-vehicle collision message for trap '{}'".format(item["name"]))

def extract_missiondef(item):
outfile = get_outfile("mission_def")
Expand Down Expand Up @@ -731,6 +735,7 @@ def extract_ter_furn_transform_messages(item):
"recipe_group": extract_recipe_group,
"scenario": extract_scenarios,
"talk_topic": extract_talk_topic,
"trap": extract_trap,
"gate": extract_gate,
"vehicle_spawn": extract_vehspawn,
"field_type": extract_field_type,
Expand Down Expand Up @@ -804,7 +809,7 @@ def writestr(filename, string, plural=None, context=None, format_strings=False,
# don't write empty strings
if not string: return

with open(filename, 'a', encoding="utf-8") as fs:
with open(filename, 'a', encoding="utf-8", newline='\n') as fs:
# Append developers comment
if comment:
tlcomment(fs, comment)
Expand Down Expand Up @@ -978,7 +983,7 @@ def extract(item, infilename):
if "footsteps" in item:
writestr(outfile, item["footsteps"], **kwargs)
wrote = True
if not wrote:
if not wrote and not "copy-from" in item:
if not warning_supressed(infilename):
print("WARNING: {}: nothing translatable found in item: {}".format(infilename, item))

Expand Down
11 changes: 11 additions & 0 deletions lang/update_pot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ then
exit 1
fi

# convert line endings to unix
if [[ $(uname -s) =~ ^(CYGWIN|MINGW)* ]]
then
echo "> Converting line endings to Unix"
if ! sed -i -e 's/\r$//' lang/po/cataclysm-dda.pot
then
echo "Line ending conversion failed. Aborting."
exit 1
fi
fi

# Final compilation check
echo "> Testing to compile the .pot file"
if ! msgfmt -c -o /dev/null lang/po/cataclysm-dda.pot
Expand Down
22 changes: 11 additions & 11 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,7 @@ void activity_handlers::start_engines_finish( player_activity *act, player *p )
"Some of the %s's engines start up.", non_muscle_started ), veh->name );
} else if( non_combustion_started > 0 ) {
//Non-combustions "engines" started
add_msg( "The %s is ready for movement.", veh->name );
add_msg( _( "The %s is ready for movement." ), veh->name );
} else {
//All of the non-muscle engines failed
add_msg( m_bad, ngettext( "The %s's engine fails to start.",
Expand Down Expand Up @@ -2885,9 +2885,9 @@ void activity_handlers::operation_do_turn( player_activity *act, player *p )
- values[3]: pl_skill
- values[4] and above: occupied body_parts
- str_values[0]: install/uninstall
- str_values[1]: cbm name
- str_values[1]: deprecated
- str_values[2]: bionic_id
- str_values[3]: upgraded cbm name
- str_values[3]: deprecated
- str_values[4]: upgraded cbm bionic_id
- str_values[5]: installer name
- str_values[6]: bool autodoc
Expand All @@ -2903,6 +2903,8 @@ void activity_handlers::operation_do_turn( player_activity *act, player *p )
is_autodoc = 6,
trait_first = 7
};
const bionic_id bid( act->str_values[cbm_id] );
const bionic_id upbid( act->str_values[upgraded_cbm_id] );
const bool autodoc = act->str_values[is_autodoc] == "true";
const bool u_see = p->is_player() ? true : g->u.sees( p->pos() ) &&
!g->u.has_effect( effect_narcosis );
Expand Down Expand Up @@ -2972,9 +2974,9 @@ void activity_handlers::operation_do_turn( player_activity *act, player *p )
add_msg( m_info, _( "The Autodoc attempts to carefully extract the bionic." ) );
}

if( p->has_bionic( bionic_id( act->str_values[cbm_id] ) ) ) {
p->perform_uninstall( bionic_id( act->str_values[cbm_id] ), act->values[0], act->values[1],
act->values[2], act->values[3], act->str_values[cbm_name] );
if( p->has_bionic( bid ) ) {
p->perform_uninstall( bid, act->values[0], act->values[1],
act->values[2], act->values[3] );
} else {
debugmsg( _( "Tried to uninstall %s, but you don't have this bionic installed." ),
act->str_values[cbm_id] );
Expand All @@ -2986,17 +2988,15 @@ void activity_handlers::operation_do_turn( player_activity *act, player *p )
add_msg( m_info, _( "The Autodoc attempts to carefully insert the bionic." ) );
}

if( bionic_id( act->str_values[cbm_id] ).is_valid() ) {
if( bid.is_valid() ) {
std::vector<trait_id> trait_to_rem;
if( act->str_values.size() > trait_first + 1 ) {
for( size_t i = trait_first; i < act->str_values.size(); i++ ) {
trait_to_rem.emplace_back( trait_id( act->str_values[i] ) );
}
}
p->perform_install( bionic_id( act->str_values[cbm_id] ),
bionic_id( act->str_values[upgraded_cbm_id] ), act->values[0], act->values[1], act->values[3],
act->str_values[cbm_name], act->str_values[upgraded_cbm_name], act->str_values[installer_name],
trait_to_rem, p->pos() );
p->perform_install( bid, upbid, act->values[0], act->values[1], act->values[3],
act->str_values[installer_name], trait_to_rem, p->pos() );
} else {
debugmsg( _( "%s is no a valid bionic_id" ), act->str_values[cbm_id] );
p->remove_effect( effect_under_op );
Expand Down
43 changes: 21 additions & 22 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ bool bionic_data::is_included( const bionic_id &id ) const
return std::find( included_bionics.begin(), included_bionics.end(), id ) != included_bionics.end();
}

bionic_data::bionic_data()
bionic_data::bionic_data() : name( no_translation( "bad bionic" ) ),
description( no_translation( "This bionic was not set up correctly, this is a bug" ) )
{
name = "bad bionic";
description = "This bionic was not set up correctly, this is a bug";
}

static void force_comedown( effect &eff )
Expand Down Expand Up @@ -248,7 +247,7 @@ bool player::activate_bionic( int b, bool eff_only )

if( bio.incapacitated_time > 0_turns ) {
add_msg( m_info, _( "Your %s is shorting out and can't be activated." ),
bionics[bio.id].name.c_str() );
bionics[bio.id].name );
return false;
}

Expand Down Expand Up @@ -714,7 +713,7 @@ bool player::deactivate_bionic( int b, bool eff_only )

if( bio.incapacitated_time > 0_turns ) {
add_msg( m_info, _( "Your %s is shorting out and can't be deactivated." ),
bionics[bio.id].name.c_str() );
bionics[bio.id].name );
return false;
}

Expand Down Expand Up @@ -1367,8 +1366,8 @@ bool player::uninstall_bionic( const bionic_id &b_id, player &installer, bool au
activity.values.push_back( bionics[b_id].capacity );
activity.values.push_back( pl_skill );
activity.str_values.push_back( "uninstall" );
activity.str_values.push_back( bionics[b_id].name );
activity.str_values.push_back( b_id.c_str() );
activity.str_values.push_back( "" );
activity.str_values.push_back( b_id.str() );
activity.str_values.push_back( "" );
activity.str_values.push_back( "" );
activity.str_values.push_back( "" );
Expand All @@ -1385,20 +1384,20 @@ bool player::uninstall_bionic( const bionic_id &b_id, player &installer, bool au
}

void player::perform_uninstall( bionic_id bid, int difficulty, int success, int power_lvl,
int pl_skill, std::string cbm_name )
int pl_skill )
{
if( success > 0 ) {

if( is_player() ) {
add_memorial_log( pgettext( "memorial_male", "Removed bionic: %s." ),
pgettext( "memorial_female", "Removed bionic: %s." ),
cbm_name );
bid.obj().name );
}

// until bionics can be flagged as non-removable
add_msg_player_or_npc( m_neutral, _( "Your parts are jiggled back into their familiar places." ),
_( "<npcname>'s parts are jiggled back into their familiar places." ) );
add_msg( m_good, _( "Successfully removed %s." ), cbm_name );
add_msg( m_good, _( "Successfully removed %s." ), bid.obj().name );
remove_bionic( bid );

// remove power bank provided by bionic
Expand All @@ -1417,7 +1416,7 @@ void player::perform_uninstall( bionic_id bid, int difficulty, int success, int
if( is_player() ) {
add_memorial_log( pgettext( "memorial_male", "Failed to remove bionic: %s." ),
pgettext( "memorial_female", "Failed to remove bionic: %s." ),
cbm_name );
bid.obj().name );
}

// for chance_of_success calculation, shift skill down to a float between ~0.4 - 30
Expand Down Expand Up @@ -1619,11 +1618,11 @@ bool player::install_bionics( const itype &type, player &installer, bool autodoc
activity.values.push_back( bionics[bioid].capacity );
activity.values.push_back( pl_skill );
activity.str_values.push_back( "install" );
activity.str_values.push_back( bionics[bioid].name );
activity.str_values.push_back( bioid.c_str() );
activity.str_values.push_back( "" );
activity.str_values.push_back( bioid.str() );
if( upbioid ) {
activity.str_values.push_back( bionics[upbioid].name );
activity.str_values.push_back( upbioid.c_str() );
activity.str_values.push_back( "" );
activity.str_values.push_back( upbioid.str() );
} else {
activity.str_values.push_back( "" );
activity.str_values.push_back( "" );
Expand Down Expand Up @@ -1651,24 +1650,24 @@ bool player::install_bionics( const itype &type, player &installer, bool autodoc
}

void player::perform_install( bionic_id bid, bionic_id upbid, int difficulty, int success,
int pl_skill, std::string cbm_name, std::string upcbm_name, std::string installer_name,
int pl_skill, std::string installer_name,
std::vector<trait_id> trait_to_rem, tripoint patient_pos )
{
if( success > 0 ) {

if( is_player() ) {
add_memorial_log( pgettext( "memorial_male", "Installed bionic: %s." ),
pgettext( "memorial_female", "Installed bionic: %s." ),
cbm_name );
bid.obj().name );
}
if( upbid != bionic_id( "" ) ) {
remove_bionic( upbid );
//~ %1$s - name of the bionic to be upgraded (inferior), %2$s - name of the upgraded bionic (superior).
add_msg( m_good, _( "Successfully upgraded %1$s to %2$s." ),
upcbm_name, cbm_name );
upbid.obj().name, bid.obj().name );
} else {
//~ %s - name of the bionic.
add_msg( m_good, _( "Successfully installed %s." ), cbm_name );
add_msg( m_good, _( "Successfully installed %s." ), bid.obj().name );
}

add_bionic( bid );
Expand All @@ -1683,7 +1682,7 @@ void player::perform_install( bionic_id bid, bionic_id upbid, int difficulty, in
if( is_player() ) {
add_memorial_log( pgettext( "memorial_male", "Failed install of bionic: %s." ),
pgettext( "memorial_female", "Failed install of bionic: %s." ),
cbm_name );
bid.obj().name );
}

// for chance_of_success calculation, shift skill down to a float between ~0.4 - 30
Expand Down Expand Up @@ -2019,8 +2018,8 @@ void load_bionic( JsonObject &jsobj )
bionic_data new_bionic;

const bionic_id id( jsobj.get_string( "id" ) );
new_bionic.name = _( jsobj.get_string( "name" ) );
new_bionic.description = _( jsobj.get_string( "description" ) );
jsobj.read( "name", new_bionic.name );
jsobj.read( "description", new_bionic.description );
new_bionic.power_activate = jsobj.get_int( "act_cost", 0 );

new_bionic.toggled = get_bool_or_flag( jsobj, "toggled", "BIONIC_TOGGLED", false );
Expand Down
5 changes: 3 additions & 2 deletions src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "bodypart.h"
#include "calendar.h"
#include "string_id.h"
#include "translations.h"
#include "type_id.h"
#include "units.h"

Expand All @@ -24,8 +25,8 @@ using itype_id = std::string;
struct bionic_data {
bionic_data();

std::string name;
std::string description;
translation name;
translation description;
/** Power cost on activation */
int power_activate = 0;
/** Power cost on deactivation */
Expand Down
4 changes: 2 additions & 2 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ static void draw_description( const catacurses::window &win, const bionic &bio )
werase( win );
const int width = getmaxx( win );
const std::string poweronly_string = build_bionic_poweronly_string( bio );
int ypos = fold_and_print( win, point_zero, width, c_white, bio.id->name );
int ypos = fold_and_print( win, point_zero, width, c_white, "%s", bio.id->name );
if( !poweronly_string.empty() ) {
ypos += fold_and_print( win, point( 0, ypos ), width, c_light_gray,
_( "Power usage: %s" ), poweronly_string );
}
ypos += 1 + fold_and_print( win, point( 0, ypos ), width, c_light_blue, bio.id->description );
ypos += 1 + fold_and_print( win, point( 0, ypos ), width, c_light_blue, "%s", bio.id->description );

// TODO: Unhide when enforcing limits
if( get_option < bool >( "CBM_SLOTS_ENABLED" ) ) {
Expand Down
20 changes: 10 additions & 10 deletions src/crafting_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int related_menu_fill( uilist &rmenu,
const std::vector<std::pair<itype_id, std::string>> &related_recipes,
const recipe_subset &available );

static std::string get_cat_name( const std::string &prefixed_name )
static std::string get_cat_unprefixed( const std::string &prefixed_name )
{
return prefixed_name.substr( 3, prefixed_name.size() - 3 );
}
Expand All @@ -80,7 +80,7 @@ void load_recipe_category( JsonObject &jsobj )
if( !is_hidden ) {
craft_cat_list.push_back( category );

const std::string cat_name = get_cat_name( category );
const std::string cat_name = get_cat_unprefixed( category );

craft_subcat_list[category] = std::vector<std::string>();
JsonArray subcats = jsobj.get_array( "recipe_subcategories" );
Expand All @@ -94,24 +94,25 @@ void load_recipe_category( JsonObject &jsobj )
}
}

static std::string get_subcat_name( const std::string &cat, const std::string &prefixed_name )
static std::string get_subcat_unprefixed( const std::string &cat, const std::string &prefixed_name )
{
std::string prefix = "CSC_" + get_cat_name( cat ) + "_";
std::string prefix = "CSC_" + get_cat_unprefixed( cat ) + "_";

if( prefixed_name.find( prefix ) == 0 ) {
return prefixed_name.substr( prefix.size(), prefixed_name.size() - prefix.size() );
}

return ( prefixed_name == "CSC_ALL" ? _( "ALL" ) : _( "NONCRAFT" ) );
return prefixed_name == "CSC_ALL" ? translate_marker( "ALL" ) : translate_marker( "NONCRAFT" );
}

static void translate_all()
{
normalized_names.clear();
for( const auto &cat : craft_cat_list ) {
normalized_names[cat] = _( get_cat_name( cat ) );
normalized_names[cat] = _( get_cat_unprefixed( cat ) );

for( const auto &subcat : craft_subcat_list[cat] ) {
normalized_names[subcat] = _( get_subcat_name( cat, subcat ) ) ;
normalized_names[subcat] = _( get_subcat_unprefixed( cat, subcat ) ) ;
}
}
}
Expand Down Expand Up @@ -151,9 +152,8 @@ static int print_items( const recipe &r, const catacurses::window &w, int ypos,

const recipe *select_crafting_recipe( int &batch_size )
{
if( normalized_names.empty() ) {
translate_all();
}
// always re-translate the category names in case the language has changed
translate_all();

const int headHeight = 3;
const int subHeadHeight = 2;
Expand Down
4 changes: 2 additions & 2 deletions src/effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,12 @@ std::string effect::disp_name() const
if( d_name.empty() ) {
return std::string();
}
ret << d_name.translated();
ret << d_name;
} else {
if( eff_type->name[0].empty() ) {
return std::string();
}
ret << eff_type->name[0].translated();
ret << eff_type->name[0];
if( intensity > 1 ) {
if( eff_type->id == "bandaged" || eff_type->id == "disinfected" ) {
ret << " [" << texitify_healing_power( intensity ) << "]";
Expand Down
2 changes: 1 addition & 1 deletion src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ class comestible_inventory_preset : public inventory_selector_preset
std::vector<bionic_id> bids = p.get_bionic_fueled_with( get_consumable_item( loc ) );
if( !bids.empty() ) {
bionic_id bid = p.get_most_efficient_bionic( bids );
cbm_name = bid->name;
cbm_name = bid->name.translated();
}
break;
}
Expand Down
Loading

0 comments on commit 60e0ca9

Please sign in to comment.