Add locale parameter to EditableText by HansMuller · Pull Request #18222 · flutter/flutter · GitHub
Skip to content

Add locale parameter to EditableText#18222

Merged
HansMuller merged 5 commits into
flutter:masterfrom
HansMuller:editable_text_locale
Jun 9, 2018
Merged

Add locale parameter to EditableText#18222
HansMuller merged 5 commits into
flutter:masterfrom
HansMuller:editable_text_locale

Conversation

@HansMuller

@HansMuller HansMuller commented Jun 5, 2018

Copy link
Copy Markdown
Contributor

The RenderParagraph and RenderEditableText renderers now pass the locale along to the engine via their internal TextPainters (see also #18189, #17879). The locale is typically defined by the app and text widgets look it up with Localizations.localeOf().

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably mention briefly what null means

@Hixie

Hixie commented Jun 8, 2018

Copy link
Copy Markdown
Contributor

As discussed offline, I realized while reviewing this patch that we do need to have the Locale on the TextStyle, because a single Text widget can have multiple parts of its text with different locales, e.g. "The English word foo is bar in Japanese and baz in Chinese" would have three locales.

The TextStyle should probably default to null locale and then Text can fill it in from the ambient Locale.

@HansMuller HansMuller force-pushed the editable_text_locale branch from 4dc7e11 to a62aba1 Compare June 8, 2018 19:12
@HansMuller HansMuller changed the title Add locale parameter to EditableText, remove it from TextStyle Add locale parameter to EditableText Jun 8, 2018
@HansMuller

Copy link
Copy Markdown
Contributor Author

The TextStyle should probably default to null locale and then Text can fill it in from the ambient Locale.

If you create a RichText with TextSpans whose TextStyles have non-null locales, the RichText will carry the ambient locale and the TextSpan styles will carry along their locales via the ui.ParagraphBuilder.

In this case the engine uses the text style's locale.

I've verified that this works. Will add tests when tests can use fonts.

    final String character = '骨';
    final TextStyle style = Theme.of(context).textTheme.display3;
    return new Scaffold(
      body: new Container(
        padding: const EdgeInsets.all(48.0),
        alignment: Alignment.center,
        child: new RichText(
          text: new TextSpan(
            children: <TextSpan>[
              new TextSpan(text: character, style: style.copyWith(locale: const Locale('ja'))),
              new TextSpan(text: character, style: style.copyWith(locale: const Locale('zh'))),
            ],
          ),
        ),
      ),
    );

@Hixie

Hixie commented Jun 8, 2018

Copy link
Copy Markdown
Contributor

Can you add the test anyway today (as a golden test) and then add a TODO to enable it, with a link to the relevant font bug? That way when we implement it we'll have a better chance to also update the test.

/// This property is rarely set. Typically the locale used to select
/// region-specific glyphs is defined by the text widget's [BuildContext]
/// using `Localizations.localeOf(context)`. For example [RichText] defines
/// its locale this way. However a rich text widget's [TextSpan]s could specify

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: comma after however

/// the Chinese and Japanese locales. In these cases the [locale] may be used
/// to select a locale-specific font.
///
/// If this value is null, a system dependent algorithm is used to select

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: system-dependent

@Hixie

Hixie commented Jun 8, 2018

Copy link
Copy Markdown
Contributor

LGTM

We should also add a test that checks that when the text style has a locale and the text has a locale, the text style one isn't replaced.

HansMuller added a commit to flutter-team-archive/goldens that referenced this pull request Jun 8, 2018
@HansMuller

HansMuller commented Jun 8, 2018

Copy link
Copy Markdown
Contributor Author

@HansMuller HansMuller merged commit 691cbee into flutter:master Jun 9, 2018
@HansMuller HansMuller deleted the editable_text_locale branch June 9, 2018 15:24
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants