Skip to content

Instantly share code, notes, and snippets.

@tricoder42
Last active November 28, 2016 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tricoder42/bc23a2ab31890efbad797763fbd1fde3 to your computer and use it in GitHub Desktop.
Save tricoder42/bc23a2ab31890efbad797763fbd1fde3 to your computer and use it in GitHub Desktop.
What style would you prefer when writing multilingual messages?
// message is constructed using helper functions
const HelperFunction = ({count}) =>
<Trans>
{plural(count, {
one: "One glass",
other: "# glasses"
})} or wine
</Trans>
// message written using template literals
const TemplateLiteral = ({count}) =>
<Trans>{`{${count}, plural, one {One glass} other {# glasses}} of wine`}</Trans>
// both examples above are transformed into this using babel-plugin,
// so it's possible to write it manually too:
const RawMessageWithParams = ({count}) =>
<Trans id="{count, plural, one {One glass} other {# glasses}} of wine" values={{count}} />
/*
Image you would have messages like this:
"{gender_of_host, select, "
"female {"
"{num_guests, plural, offset:1 "
"=0 {{host} does not give a party.}"
"=1 {{host} invites {guest} to her party.}"
"=2 {{host} invites {guest} and one other person to her party.}"
"other {{host} invites {guest} and # other people to her party.}}}"
"male {"
"{num_guests, plural, offset:1 "
"=0 {{host} does not give a party.}"
"=1 {{host} invites {guest} to his party.}"
"=2 {{host} invites {guest} and one other person to his party.}"
"other {{host} invites {guest} and # other people to his party.}}}"
"other {"
"{num_guests, plural, offset:1 "
"=0 {{host} does not give a party.}"
"=1 {{host} invites {guest} to their party.}"
"=2 {{host} invites {guest} and one other person to their party.}"
"other {{host} invites {guest} and # other people to their party.}}}}"
Source: http://userguide.icu-project.org/formatparse/messages
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment