Skip to content

[web] Localizations.override sets <html lang> for the whole page and does not restore it #194696

Closed

Description

@T-Davis

Steps to reproduce

  1. Run flutter create --platforms web bug and replace lib/main.dart with the code sample below.
  2. Run flutter build web, then serve it with python3 -m http.server -d build/web.
  3. Open http://localhost:8000 and wait for it to show "Hola", which is inside a Localizations.override for Locale('es', 'US').
  4. Run this in the DevTools console: document.documentElement.lang
  5. Click anywhere on the page. "Hola" becomes "Hello", which is outside any override.
  6. Run the same query again.

Expected results

"en-US" both times. That is the app's own locale, the first of WidgetsApp's default supportedLocales. The Localizations.override docs say it "Overrides the inherited Locale or LocalizationsDelegates for child", and point to WidgetsApp.locale for changing the locale of an entire app.

Actual results

"es-US" both times. A subtree override sets the language of the whole page, and the page keeps it after the override leaves the tree. After the click, the <flutter-view> element matches :lang(es) and not :lang(en), so the browser treats the whole app as Spanish. The same app with _showOverride starting false gives "en-US".

Measured on 3.47.7 stable and on master at 56f0dcb, in release builds, with Playwright's Chromium 156, Firefox 157 and WebKit 27.2 builds. A --wasm build gives the same result in Chromium. Firefox and WebKit did not load the wasm module.

_LocalizationsState.locale's setter calls platformDispatcher.setApplicationLocale for every Localizations, including the one Localizations.override creates, which leaves isApplicationLevel at its default of false. On web, setApplicationLocale passes the locale to every view, and the full-page embedding writes it to <html lang>. Nothing calls it again when the override is disposed, and the app-level Localizations only calls it when its own locale changes.

Calling setApplicationLocale only when widget.isApplicationLevel is true fixes the repro. With that change applied to 3.47.7, it gives "en-US" both times in all three engines, and the app without the override still gives "en-US". The same file already checks isApplicationLevel before setting localeForSubtree.

The call came in #175100, and #177284 made the web engine act on it. No framework test checks what a nested Localizations sends.

Only web was run. From reading the source, Android and iOS receive the override's locale too, since the call is in the framework.

Related: #194688, where the override's own subtree gets lang="es_US".

Code sample

Code sample
import 'package:flutter/widgets.dart';

void main() => runApp(const App());

class App extends StatefulWidget {
  const App({super.key});

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  bool _showOverride = true;

  @override
  Widget build(BuildContext context) {
    return WidgetsApp(
      color: const Color(0xFF000000),
      builder: (context, _) => GestureDetector(
        behavior: HitTestBehavior.opaque,
        // Tap anywhere to remove the override.
        onTap: () => setState(() => _showOverride = false),
        child: _showOverride
            ? Localizations.override(
                context: context,
                locale: const Locale('es', 'US'),
                child: const Text('Hola'),
              )
            : const Text('Hello'),
      ),
    );
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Home directory paths, the iPhone's name and device IDs are replaced with <redacted>. The runs used Playwright's browsers, not the Chrome 155 listed here.

Doctor output
[✓] Flutter (Channel stable, 3.47.7, on macOS 26.5.1 25F80 darwin-arm64, locale en-US) [530ms]
    • Flutter version 3.47.7 on channel stable at <redacted>/fvm/versions/3.47.7
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision abaf9c5237 (10 days ago), 2026-10-08 09:51:21 -0700
    • Engine revision deb287481e
    • Dart version 3.13.5
    • DevTools version 2.60.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [1,428ms]
    • Android SDK at <redacted>/Library/Android/sdk
    • Emulator version 37.1.11.0 (build_id 15917651) (CL:N/A)
    • Platform android-36.1, build-tools 36.1.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 25.0.3+-15898627-b508.16)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 26.3) [1,214ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 17C529
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [4ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Connected device (4 available) [12.0s]
    • Pixel 7 Pro (mobile)         • <redacted>            • android-arm64  • Android 17 (API 37)
    • <redacted> (mobile) • <redacted> • ios            • iOS 26.7.1 23H30
    • macOS (desktop)              • macos                     • darwin-arm64   • macOS 26.5.1 25F80 darwin-arm64
    • Chrome (web)                 • chrome                    • web-javascript • Google Chrome 155.0.8059.80

[✓] Network resources [582ms]
    • All expected network resources are available.

• No issues found!

Activity

  1. suryaKommana2662 commented on Oct 20, 2026

    @suryaKommana2662
    Contributor

    @T-Davis Thanks for the report. I was able to reproduce the issue. After clicking to remove the Localizations.override subtree, the text changes from Hola to Hello, but document.documentElement.lang remains es-US instead of the expected en-US.

    Flutter Doctor Output

    [✓] Flutter (Channel stable, 3.47.7, on macOS 27.0 26A428 darwin-arm64, locale en-IN) [282ms]
        • Flutter version 3.47.7 on channel stable at /Users/suryakommana/develop/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision abaf9c5237 (12 days ago), 2026-10-08 09:51:21 -0700
        • Engine revision deb287481e
        • Dart version 3.13.5
        • DevTools version 2.60.0
        • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets,
          enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [1,520ms]
        • Android SDK at /Users/suryakommana/Library/Android/sdk
        • Emulator version 37.1.11.0 (build_id 15917651) (CL:N/A)
        • Platform android-37.0, build-tools 36.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 25.0.2+-15348964-b329.117)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 27.1) [758ms]
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 27A9275
        • CocoaPods version 1.17.0
    
    [✓] Chrome - develop for the web [3ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Connected device (3 available) [5.9s]
        • sdk gphone16k arm64 (mobile) • emulator-5554 • android-arm64  • Android 17 (API 37) (emulator)
        • macOS (desktop)              • macos         • darwin-arm64   • macOS 27.0 26A428 darwin-arm64
        • Chrome (web)                 • chrome        • web-javascript • Google Chrome 155.0.8059.84
    
    [✓] Network resources [833ms]
        • All expected network resources are available.
    
    • No issues found!
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    a: internationalizationSupporting other languages or locales. (aka i18n)
    platform-webWeb applications specifically
    fyi-webFor the attention of Web platform team
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    a: internationalizationSupporting other languages or locales. (aka i18n)
    platform-webWeb applications specifically
    fyi-webFor the attention of Web platform team
    on Oct 20, 2026
  3. 7 remaining items

  4. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    platform-webWeb applications specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    fyi-webFor the attention of Web platform team
    on Oct 20, 2026
  5. self-assigned this
    on Oct 20, 2026
  6. added
    team-webOwned by Web platform team
    and removed on Oct 20, 2026
  7. Renzo-Olivares commented on Oct 20, 2026

    @Renzo-Olivares
    Contributor

    from triage: routing to web team for further investigation but feel free to route back to framework if this is not the case.

  8. github-actions commented on Nov 4, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  9. locked as resolved and limited conversation to collaborators on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: internationalizationSupporting other languages or locales. (aka i18n)frameworkflutter/packages/flutter repository. See also f: labels.fyi-webFor the attention of Web platform teamhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyteam-webOwned by Web platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions