text
stringlengths
1
372
children: <widget>[
// returns 'hello john'
Text(AppLocalizations.of(context)!.hello('John')),
],
);
<code_end>
you can also use numerical placeholders to specify multiple values.
different languages have different ways to pluralize words.
the syntax also supports specifying how a word should be pluralized.
a pluralized message must include a num parameter indicating
how to pluralize the word in different situations.
english, for example, pluralizes “person” to “people”,
but that doesn’t go far enough.
the message0 plural might be “no people” or “zero people”.
the messageFew plural might be
“several people”, “some people”, or “a few people”.
the messageMany plural might
be “most people” or “many people”, or “a crowd”.
only the more general messageOther field is required.
the following example shows what options are available:
the previous expression is replaced by the message variation
(message0, message1, …) corresponding to the value
of the countPlaceholder.
only the messageOther field is required.
the following example defines a message that pluralizes
the word, “wombat”:
<code_start>
"nwombats": "{count, plural, =0{no wombats} =1{1 wombat} other{{count} wombats}}",
"@nwombats": {
"description": "a plural message",
"placeholders": {
"count": {
"type": "num",
"format": "compact"
}
}
}
<code_end>
use a plural method by passing in the count parameter:
<code_start>
// examples of internationalized strings.
return column(
children: <widget>[
...
// returns 'no wombats'
Text(AppLocalizations.of(context)!.nWombats(0)),
// returns '1 wombat'
Text(AppLocalizations.of(context)!.nWombats(1)),
// returns '5 wombats'
Text(AppLocalizations.of(context)!.nWombats(5)),
],
);
<code_end>
similar to plurals,
you can also choose a value based on a string placeholder.
this is most often used to support gendered languages.
the syntax is as follows:
the next example defines a message that
selects a pronoun based on gender:
<code_start>
"pronoun": "{gender, select, male{he} female{she} other{they}}",
"@pronoun": {
"description": "a gendered message",
"placeholders": {
"gender": {
"type": "string"
}
}
}
<code_end>
use this feature by
passing the gender string as a parameter:
<code_start>
// examples of internationalized strings.
return column(
children: <widget>[
...
// returns 'he'
Text(AppLocalizations.of(context)!.pronoun('male')),
// returns 'she'
Text(AppLocalizations.of(context)!.pronoun('female')),
// returns 'they'
Text(AppLocalizations.of(context)!.pronoun('other')),
],
);
<code_end>
keep in mind that when using select statements,
comparison between the parameter and the actual
value is case-sensitive.
that is, AppLocalizations.of(context)!.pronoun("Male")
defaults to the “other” case, and returns “they”.
<topic_end>
<topic_start>
escaping syntax
sometimes, you have to use tokens,
such as { and }, as normal characters.
to ignore such tokens from being parsed,
enable the use-escaping flag by adding the
following to l10n.yaml:
the parser ignores any string of characters