Skip to content

Commit

Permalink
Migrate bodypart names to class translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrox committed Feb 7, 2020
1 parent ff590a0 commit 8ebd79c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
22 changes: 22 additions & 0 deletions data/json/body_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"id": "torso",
"type": "body_part",
"name": "torso",
"accusative": { "ctxt": "bodypart_accusative", "str": "torso" },
"heading": "Torso",
"heading_multiple": "Torso",
"hp_bar_ui_text": "TORSO",
Expand All @@ -20,6 +21,7 @@
"id": "head",
"type": "body_part",
"name": "head",
"accusative": { "ctxt": "bodypart_accusative", "str": "head" },
"heading": "Head",
"heading_multiple": "Head",
"hp_bar_ui_text": "HEAD",
Expand All @@ -37,6 +39,7 @@
"id": "eyes",
"type": "body_part",
"name": "eyes",
"accusative": { "ctxt": "bodypart_accusative", "str": "eyes" },
"heading": "Eyes",
"heading_multiple": "Eyes",
"encumbrance_text": "Ranged combat is hampered.",
Expand All @@ -53,6 +56,7 @@
"id": "mouth",
"type": "body_part",
"name": "mouth",
"accusative": { "ctxt": "bodypart_accusative", "str": "mouth" },
"heading": "Mouth",
"heading_multiple": "Mouth",
"encumbrance_text": "Running is slowed.",
Expand All @@ -68,8 +72,11 @@
{
"id": "arm_l",
"type": "body_part",
"//": "See comments in `body_part_struct::load` of bodypart.cpp about why xxx and xxx_multiple are not inside a single translation object.",
"name": "left arm",
"name_multiple": "arms",
"accusative": { "ctxt": "bodypart_accusative", "str": "left arm" },
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "arms" },
"heading": "L. Arm",
"heading_multiple": "Arms",
"encumbrance_text": "Melee and ranged combat is hampered.",
Expand All @@ -88,6 +95,8 @@
"type": "body_part",
"name": "right arm",
"name_multiple": "arms",
"accusative": { "ctxt": "bodypart_accusative", "str": "right arm" },
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "arms" },
"heading": "R. Arm",
"heading_multiple": "Arms",
"hp_bar_ui_text": "R ARM",
Expand All @@ -106,6 +115,8 @@
"type": "body_part",
"name": "left hand",
"name_multiple": "hands",
"accusative": { "ctxt": "bodypart_accusative", "str": "left hand" },
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "hands" },
"heading": "L. Hand",
"heading_multiple": "Hands",
"encumbrance_text": "Manual tasks are slowed.",
Expand All @@ -123,6 +134,8 @@
"type": "body_part",
"name": "right hand",
"name_multiple": "hands",
"accusative": { "ctxt": "bodypart_accusative", "str": "right hand" },
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "hands" },
"heading": "R. Hand",
"heading_multiple": "Hands",
"encumbrance_text": "Manual tasks are slowed.",
Expand All @@ -140,6 +153,8 @@
"type": "body_part",
"name": "left leg",
"name_multiple": "legs",
"accusative": { "ctxt": "bodypart_accusative", "str": "left leg" },
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "legs" },
"heading": "L. Leg",
"heading_multiple": "Legs",
"hp_bar_ui_text": "L LEG",
Expand All @@ -158,6 +173,8 @@
"type": "body_part",
"name": "right leg",
"name_multiple": "legs",
"accusative": { "ctxt": "bodypart_accusative", "str": "right leg" },
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "legs" },
"heading": "R. Leg",
"heading_multiple": "Legs",
"hp_bar_ui_text": "R LEG",
Expand All @@ -176,6 +193,8 @@
"type": "body_part",
"name": "left foot",
"name_multiple": "feet",
"accusative": { "ctxt": "bodypart_accusative", "str": "left foot" },
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "feet" },
"heading": "L. Foot",
"heading_multiple": "Feet",
"encumbrance_text": "Running is slowed.",
Expand All @@ -193,6 +212,8 @@
"type": "body_part",
"name": "right foot",
"name_multiple": "feet",
"accusative": { "ctxt": "bodypart_accusative", "str": "right foot" },
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "feet" },
"heading": "R. Foot",
"heading_multiple": "Feet",
"encumbrance_text": "Running is slowed.",
Expand All @@ -209,6 +230,7 @@
"id": "num_bp",
"type": "body_part",
"name": "appendix",
"accusative": { "ctxt": "bodypart_accusative", "str": "appendix" },
"heading": "appendix",
"heading_multiple": "Appendices",
"encumbrance_text": "It's inflamed.",
Expand Down
25 changes: 14 additions & 11 deletions src/bodypart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "anatomy.h"
#include "debug.h"
#include "generic_factory.h"
#include "translations.h"
#include "json.h"

side opposite_side( side s )
Expand Down Expand Up @@ -189,6 +188,11 @@ void body_part_struct::load( const JsonObject &jo, const std::string & )
// without plural forms, translation of this string would indicate it
// to be a left or right part, while it is not.
optional( jo, was_loaded, "name_multiple", name_multiple );

mandatory( jo, was_loaded, "accusative", accusative );
// same as the above comment
optional( jo, was_loaded, "accusative_multiple", accusative_multiple );

mandatory( jo, was_loaded, "heading", name_as_heading );
// Same as the above comment
mandatory( jo, was_loaded, "heading_multiple", name_as_heading_multiple );
Expand Down Expand Up @@ -260,29 +264,28 @@ void body_part_struct::check() const
}
}

// Some languages do not have plural forms, so we don't use ngettext()/npgettext()
// in the 3 following methods so the singular and plural strings can be properly
// translated for these languages.
std::string body_part_name( body_part bp, int number )
{
const auto &bdy = get_bp( bp );
return number > 1 ? _( bdy.name_multiple ) : _( bdy.name );
// See comments in `body_part_struct::load` about why these two strings are
// not a single translation object with plural enabled.
return number > 1 ? bdy.name_multiple.translated() : bdy.name.translated();
}

std::string body_part_name_accusative( body_part bp, int number )
{
const auto &bdy = get_bp( bp );
if( number > 1 ) {
return pgettext( "bodypart_accusative", bdy.name_multiple.c_str() );
} else {
return pgettext( "bodypart_accusative", bdy.name.c_str() );
}
// See comments in `body_part_struct::load` about why these two strings are
// not a single translation object with plural enabled.
return number > 1 ? bdy.accusative_multiple.translated() : bdy.accusative.translated();
}

std::string body_part_name_as_heading( body_part bp, int number )
{
const auto &bdy = get_bp( bp );
return number > 1 ? _( bdy.name_as_heading_multiple ) : _( bdy.name_as_heading );
// See comments in `body_part_struct::load` about why these two strings are
// not a single translation object with plural enabled.
return number > 1 ? bdy.name_as_heading_multiple.translated() : bdy.name_as_heading.translated();
}

std::string body_part_hp_bar_ui_text( body_part bp )
Expand Down
11 changes: 7 additions & 4 deletions src/bodypart.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "int_id.h"
#include "string_id.h"
#include "translations.h"

class JsonObject;
template <typename E> struct enum_traits;
Expand Down Expand Up @@ -70,10 +71,12 @@ struct body_part_struct {
bool was_loaded = false;

// Those are stored untranslated
std::string name;
std::string name_multiple;
std::string name_as_heading;
std::string name_as_heading_multiple;
translation name;
translation name_multiple;
translation accusative;
translation accusative_multiple;
translation name_as_heading;
translation name_as_heading_multiple;
std::string hp_bar_ui_text;
std::string encumb_text;
// Legacy "string id"
Expand Down

0 comments on commit 8ebd79c

Please sign in to comment.