Skip to content

[ Widget Previews ] Add support for localizations in widget previews #169229

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

bkonyi
Copy link
Contributor

@bkonyi bkonyi commented May 21, 2025

This change adds a new localizations property to the Preview annotation, which takes a callback that returns a
PreviewLocalizationsData object. This class contains the same localization properties that can be provided to WidgetsApp and other similar widgets.

This change also refactors much of the localization resolution logic into a shared LocalizationsResolver class to allow for localization resolution to be done in the widget preview scaffold on a per-preview basis.

Fixes #166433

This change adds a new `localizations` property to the `Preview`
annotation, which takes a callback that returns a
`PreviewLocalizationsData` object. This class contains the same
localization properties that can be provided to `WidgetsApp` and other
similar widgets.

This change also refactors much of the localization resolution logic
into a shared `LocalizationsResolver` class to allow for localization
resolution to be done in the widget preview scaffold on a per-preview
basis.

Fixes #166433
@github-actions github-actions bot added tool Affects the "flutter" command-line tool. See also t: labels. framework flutter/packages/flutter repository. See also f: labels. labels May 21, 2025
/// Creates a collection of localization objects and callbacks for use in
/// widget previews.
const PreviewLocalizationsData({
this.locale,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm wondering if the locale property should be a member of Preview instead as the PreviewLocalizationsData is probably going to be the same across the entire application, but users will likely want to create previews for different locales. Thoughts?

@bkonyi bkonyi requested review from jyameo and Piinks May 22, 2025 20:36
@bkonyi bkonyi marked this pull request as ready for review May 22, 2025 20:36
@bkonyi
Copy link
Contributor Author

bkonyi commented May 22, 2025

@Piinks, when you have a chance, can you review the additions to the framework and refactoring of localization resolution into a shared class? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework flutter/packages/flutter repository. See also f: labels. tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I18N: Support for previewing different locales
1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy