Content-Length: 293281 | pFad | https://github.com/flutter/flutter/issues/147974

E0 [Proposal] Support rich text in `flutter gen-l10n` · Issue #147974 · flutter/flutter · GitHub
Skip to content

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

@navaronbracke

Description

@navaronbracke

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: internationalizationSupporting other languages or locales. (aka i18n)c: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.triaged-toolTriaged by Flutter Tool teamwould require significant investmentA PR would not be accepted without a plan for ongoing support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/flutter/flutter/issues/147974

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy