facebook/fbt

how to generate more pronouns variations for translations?

Closed this issue · 2 comments

HI, I wanted to understand how can I add more pronouns to be generated for translations:
e.g checking the builtin demo of FBT

                <fbt desc="Example enum & pronoun">
                  <fbt:param name="name">
                    <b className="padRight">
                      <a href="#">{this.state.ex2Name}</a>
                    </b>
                  </fbt:param>
                  has a
                  <fbt:enum
                    enum-range={ExampleEnum}
                    value={this.state.ex2Object}
                  />
                  to share!{' '}
                  <b className="pad">
                    <a href="#">View</a>
                  </b>{' '}
                  <fbt:pronoun
                    type="possessive"
                    gender={this.state.ex2Pronoun}
                    human="true"
                  />{' '}
                  <fbt:enum
                    enum-range={ExampleEnum}
                    value={this.state.ex2Object}
                  />.
                </fbt>

will generate the following variations when collecting the strings

   "hashToText": {
    "Yjqpv79V3JSE255LFP0AAA==": "{name} has a link to share! {=View} her link.",
    "pmznwyWXEqrG9HZwb5aGsQ==": "{name} has a link to share! {=View} his link.",
    "/JQB0l8rEd+B7ae/lcLlVg==": "{name} has a link to share! {=View} their link.",
    "fS9yqVLDDYOA627Xuxrxvw==": "{name} has a page to share! {=View} her page.",
    "1gXZoVTrxY6d3TSX5/KrXg==": "{name} has a page to share! {=View} his page.",
    "ocUjztl+ZCTxysGLukn+kw==": "{name} has a page to share! {=View} their page.",
    "z67lDQSKUy/LXrqrRHj3aw==": "{name} has a photo to share! {=View} her photo.",
    "1PKQnkF/lWmk79Tv/ys24A==": "{name} has a photo to share! {=View} his photo.",
    "95jC7mDsBpqzCbCA3504zw==": "{name} has a photo to share! {=View} their photo.",
    "7y2mltlG5nn8ihCz2AK1AQ==": "{name} has a post to share! {=View} her post.",
    "FT9sU8nTJmNxzV6HXQDOdA==": "{name} has a post to share! {=View} his post.",
    "Izavl3nyjFZGvIPhvrJYMA==": "{name} has a post to share! {=View} their post.",
    "9fe4WrzDx/G3g9xlON2txA==": "{name} has a video to share! {=View} her video.",
    "I3OyaQ+VNY1GA++1dByInA==": "{name} has a video to share! {=View} his video.",
    "N4hL52x52Phrk/Bzp1RkTg==": "{name} has a video to share! {=View} their video."
   },

but, this makes perfect sense for english, but in other languages it's missing cases (e.g in Hebrew I need also pulral_male, plural_female variations)
and Indeed in pronoun enum set they exist as can be seen in the table https://facebook.github.io/fbt/docs/pronouns

But I am not sure how to add new values? my guess was that I need to manually edit the jsfbt and add more cases, but then how can I know which hash to set?
thanks in advance!

Hey!

Unfortunately, internally at FB, we still default to "UNKNOWN" and effectively use MALE_PLURAL for this case, given that it's exceedingly rare to see FEMALE_PLURAL used in practice. That doesn't mean this is ideal, nor that it works for everyone's use case.

Additionally, FBT is only really tested and supported internally for extracting English source text. So you'll only ever end up with 3-4 options when using fbt:pronoun

In this particular case, you could support your female plural case with some careful coordination between your translations and the source code.
By passing in a gender to fbt:name, you can then "variate" on name's gender at runtime, and you could specifically do this for the female plural case of the "UNKNOWN" pronoun case.

                <fbt desc="Example enum & pronoun">
                  <fbt:param name="name" gender={this.state.ex2Gender}>
                    <b className="padRight">
                      <a href="#">{this.state.ex2Name}</a>
                    </b>
                  </fbt:param>
                  ...
                </fbt>

When translating, you can then variate the gender in the plural forms for the results of the "UNKNOWN" case hashes (/JQB0l8rEd+B7ae/lcLlVg==, ocUjztl+ZCTxysGLukn+kw==, 95jC7mDsBpqzCbCA3504zw==, Izavl3nyjFZGvIPhvrJYMA==)

Then when passing translations to the translation script for those, for Hebrew, you can provide an alternative translation for that pronoun when the gender passed to name is female.

Notice here, that our workaround relies on using fbt:name. If you didn't have an fbt:name on which you could rely on variating the gender, you'd have to use fbt:subject if you wanted to get this particular case correct. Again, you'd have to add the corresponding translations to get this to work at runtime.

Let me know if that makes sense!

@barakd, feel free to re-open if you have more questions