[Proposal] Support rich text in flutter gen-l10n
#147974
Labels
a: internationalization
Supporting other languages or locales. (aka i18n)
c: new feature
Nothing broken; request for a new capability
c: proposal
A detailed proposal for a change to Flutter
team-tool
Owned by Flutter Tool team
tool
Affects the "flutter" command-line tool. See also t: labels.
Use case
Currently when using
flutter gen-l10n
, there is no built-in support for generating translations that might requireText.rich()
widgets with different text styles for specific elements in the text.Users have to resort to defining multiple individual strings, along with manually stitching together the Text.rich() widgets.
Proposal
Extend the
flutter gen-l10n
tool, so that it supports generating aText.rich()
using a function, rather than just aString
for the text.A good middle ground would be to update the generator so that it can generate the following:
This way, the base
TextSpan()
s can take the base styling fromText.rich()
but theInlineSpan
can be provided a TextStyle by the user (using a manually provided TextSpan). For the generated TextSpan's you lose out on the extra parameters, though.Perhaps we could use a new format hint, i.e.
richText
in the ARB metadata, to determine how to interpret the values.Although, using the existing "placeholders" metadata part might not be sufficient, as one could then easily mix up the different placeholders. We might be able to stringify primitives though, but for the first implementation I'd rather keep the InlineSpan inputs separate from anything else, to reduce complexity.
The text was updated successfully, but these errors were encountered: