Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Support rich text in flutter gen-l10n #147974

Open
Tracked by #130635
navaronbracke opened this issue May 8, 2024 · 0 comments
Open
Tracked by #130635

[Proposal] Support rich text in flutter gen-l10n #147974

navaronbracke opened this issue May 8, 2024 · 0 comments
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.

Comments

@navaronbracke
Copy link
Contributor

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.

@danagbemava-nc danagbemava-nc added in triage Presently being triaged by the triage team c: new feature Nothing broken; request for a new capability tool Affects the "flutter" command-line tool. See also t: labels. a: internationalization Supporting other languages or locales. (aka i18n) c: proposal A detailed proposal for a change to Flutter team-tool Owned by Flutter Tool team and removed in triage Presently being triaged by the triage team labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

2 participants