Skip to content

Commit

Permalink
Merge pull request #37807 from Qrox/bodypart-names
Browse files Browse the repository at this point in the history
Body part names refactor
  • Loading branch information
ZhilkinSerg authored Feb 7, 2020
2 parents 5079712 + eeee409 commit 63798be
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 58 deletions.
90 changes: 56 additions & 34 deletions data/json/body_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"id": "torso",
"type": "body_part",
"name": "torso",
"heading_singular": "Torso",
"heading_plural": "Torso",
"accusative": { "ctxt": "bodypart_accusative", "str": "torso" },
"heading": "Torso",
"heading_multiple": "Torso",
"hp_bar_ui_text": "TORSO",
"encumbrance_text": "Dodging and melee is hampered.",
"main_part": "torso",
Expand All @@ -20,8 +21,9 @@
"id": "head",
"type": "body_part",
"name": "head",
"heading_singular": "Head",
"heading_plural": "Head",
"accusative": { "ctxt": "bodypart_accusative", "str": "head" },
"heading": "Head",
"heading_multiple": "Head",
"hp_bar_ui_text": "HEAD",
"encumbrance_text": "",
"main_part": "head",
Expand All @@ -37,8 +39,9 @@
"id": "eyes",
"type": "body_part",
"name": "eyes",
"heading_singular": "Eyes",
"heading_plural": "Eyes",
"accusative": { "ctxt": "bodypart_accusative", "str": "eyes" },
"heading": "Eyes",
"heading_multiple": "Eyes",
"encumbrance_text": "Ranged combat is hampered.",
"main_part": "head",
"opposite_part": "eyes",
Expand All @@ -53,8 +56,9 @@
"id": "mouth",
"type": "body_part",
"name": "mouth",
"heading_singular": "Mouth",
"heading_plural": "Mouth",
"accusative": { "ctxt": "bodypart_accusative", "str": "mouth" },
"heading": "Mouth",
"heading_multiple": "Mouth",
"encumbrance_text": "Running is slowed.",
"main_part": "head",
"opposite_part": "mouth",
Expand All @@ -68,10 +72,13 @@
{
"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_plural": "arms",
"heading_singular": "L. Arm",
"heading_plural": "Arms",
"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.",
"hp_bar_ui_text": "L ARM",
"main_part": "arm_l",
Expand All @@ -87,9 +94,11 @@
"id": "arm_r",
"type": "body_part",
"name": "right arm",
"name_plural": "arms",
"heading_singular": "R. Arm",
"heading_plural": "Arms",
"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",
"encumbrance_text": "Melee and ranged combat is hampered.",
"main_part": "arm_r",
Expand All @@ -105,9 +114,11 @@
"id": "hand_l",
"type": "body_part",
"name": "left hand",
"name_plural": "hands",
"heading_singular": "L. Hand",
"heading_plural": "Hands",
"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.",
"main_part": "arm_l",
"opposite_part": "hand_r",
Expand All @@ -122,9 +133,11 @@
"id": "hand_r",
"type": "body_part",
"name": "right hand",
"name_plural": "hands",
"heading_singular": "R. Hand",
"heading_plural": "Hands",
"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.",
"main_part": "arm_r",
"opposite_part": "hand_l",
Expand All @@ -139,9 +152,11 @@
"id": "leg_l",
"type": "body_part",
"name": "left leg",
"name_plural": "legs",
"heading_singular": "L. Leg",
"heading_plural": "Legs",
"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",
"encumbrance_text": "Running and swimming are slowed.",
"main_part": "leg_l",
Expand All @@ -157,9 +172,11 @@
"id": "leg_r",
"type": "body_part",
"name": "right leg",
"name_plural": "legs",
"heading_singular": "R. Leg",
"heading_plural": "Legs",
"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",
"encumbrance_text": "Running and swimming are slowed.",
"main_part": "leg_r",
Expand All @@ -175,9 +192,11 @@
"id": "foot_l",
"type": "body_part",
"name": "left foot",
"name_plural": "feet",
"heading_singular": "L. Foot",
"heading_plural": "Feet",
"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.",
"main_part": "leg_l",
"opposite_part": "foot_r",
Expand All @@ -192,9 +211,11 @@
"id": "foot_r",
"type": "body_part",
"name": "right foot",
"name_plural": "feet",
"heading_singular": "R. Foot",
"heading_plural": "Feet",
"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.",
"main_part": "leg_r",
"opposite_part": "foot_l",
Expand All @@ -209,8 +230,9 @@
"id": "num_bp",
"type": "body_part",
"name": "appendix",
"heading_singular": "appendix",
"heading_plural": "Appendices",
"accusative": { "ctxt": "bodypart_accusative", "str": "appendix" },
"heading": "appendix",
"heading_multiple": "Appendices",
"encumbrance_text": "It's inflamed.",
"main_part": "num_bp",
"opposite_part": "num_bp",
Expand Down
1 change: 1 addition & 0 deletions doc/TRANSLATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ issues reported by the `translation` class.
| Inscribe use action verbs/gerunds
| Monster names (plural supported) and descriptions
| Snippets
| Bodypart names

### Recommendations

Expand Down
14 changes: 8 additions & 6 deletions lang/extract_json_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,16 @@ def extract_harvest(item):

def extract_bodypart(item):
outfile = get_outfile("bodypart")
# See comments in `body_part_struct::load` of bodypart.cpp about why xxx and xxx_multiple are not inside a single translation object.
writestr(outfile, item["name"])
writestr(outfile, item["name"], context="bodypart_accusative")
if "name_plural" in item:
writestr(outfile, item["name_plural"])
writestr(outfile, item["name_plural"], context="bodypart_accusative")
if "name_multiple" in item:
writestr(outfile, item["name_multiple"])
writestr(outfile, item["accusative"])
if "accusative_multiple" in item:
writestr(outfile, item["accusative_multiple"])
writestr(outfile, item["encumbrance_text"])
writestr(outfile, item["heading_singular"])
writestr(outfile, item["heading_plural"])
writestr(outfile, item["heading"])
writestr(outfile, item["heading_multiple"])
if "hp_bar_ui_text" in item:
writestr(outfile, item["hp_bar_ui_text"])

Expand Down
37 changes: 23 additions & 14 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 @@ -183,9 +182,20 @@ void body_part_struct::load( const JsonObject &jo, const std::string & )
mandatory( jo, was_loaded, "id", id );

mandatory( jo, was_loaded, "name", name );
optional( jo, was_loaded, "name_plural", name_multiple );
mandatory( jo, was_loaded, "heading_singular", name_as_heading_singular );
mandatory( jo, was_loaded, "heading_plural", name_as_heading_multiple );
// This is NOT the plural of `name`; it's a name refering to the pair of
// bodyparts which this bodypart belongs to, and thus should not be implemented
// using "ngettext" or "translation::make_plural". Otherwise, in languages
// 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 );
optional( jo, was_loaded, "hp_bar_ui_text", hp_bar_ui_text );
mandatory( jo, was_loaded, "encumbrance_text", encumb_text );
mandatory( jo, was_loaded, "hit_size", hit_size );
Expand Down Expand Up @@ -254,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_singular );
// 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_singular;
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 63798be

Please sign in to comment.