text stringlengths 1 474 |
|---|
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 |
wrapped with a pair of single quotes. |
To use a normal single quote character, |
use a pair of consecutive single quotes. |
For example, the follow text is converted |
to a Dart String:The resulting string is as follows:<topic_end> |
<topic_start> |
Messages with numbers and currencies |
Numbers, including those that represent currency values, |
are displayed very differently in different locales. |
The localizations generation tool in |
flutter_localizations uses the |
NumberFormat |
class in the intl package to format |
numbers based on the locale and the desired format.The int, double, and number types can use any of the |
following NumberFormat constructors:The starred NumberFormat constructors in the table |
offer optional, named parameters. |
Those parameters can be specified as the value |
of the placeholder’s optionalParameters object. |
For example, to specify the optional decimalDigits |
parameter for compactCurrency, |
make the following changes to the lib/l10n/app_en.arg file: |
<code_start>"numberOfDataPoints": "Number of data points: {value}", |
"@numberOfDataPoints": { |
"description": "A message with a formatted int parameter", |
"placeholders": { |
"value": { |
"type": "int", |
"format": "compactCurrency", |
"optionalParameters": { |
"decimalDigits": 2 |
} |
} |
} |
}<code_end> |
<topic_end> |
<topic_start> |
Messages with dates |
Dates strings are formatted in many different ways |
depending both the locale and the app’s needs.Placeholder values with type DateTime are formatted with |
DateFormat in the intl package.There are 41 format variations, |
identified by the names of their DateFormat factory constructors. |
In the following example, the DateTime value |
that appears in the helloWorldOn message is |
formatted with DateFormat.yMd:In an app where the locale is US English, |
the following expression would produce “7/9/1959”. |
In a Russian locale, it would produce “9.07.1959”.<topic_end> |
<topic_start> |
Localizing for iOS: Updating the iOS app bundle |
Typically, iOS applications define key application metadata, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.