-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Description
Use case
Currently when using flutter gen-l10n
, there is no built-in support for generating translations that might require Text.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 a Text.rich()
using a function, rather than just a String
for the text.
A good middle ground would be to update the generator so that it can generate the following:
TextSpan someTranslation({required InlineSpan parameterOne, required InlineSpan parameterTwo}) {
return TextSpan(
children: <InlineSpan>[
const TextSpan(text: 'Part of the translated string'),
parameterOne,
const TextSpan(text: 'Another part of the translated string'),
parameterTwo,
],
);
}
This way, the base TextSpan()
s can take the base styling from Text.rich()
but the InlineSpan
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.