Skip to content

Why Localizations.localOf(context).toLanguageTag() returns me incorrect value for some languages? #161871

@hello-nico-chan

Description

@hello-nico-chan

Steps to reproduce

There are not many more steps, just switch the language in app settings and print the Localizations.locale (context).toLanguageTag().toLowerCase(), then check the result.
Please check the video on my real device; the language code is at the bottom of the settings page. I tested these languages:

language expected actual correct?
en-gb en-gb en-gb
en-nz en-nz en-nz
en-us en-us en-au
zh-cn zh-cn zh-cn
zh-tw zh-tw zh-cn

Flutter 3.24.3
Dart 3.5.3
DevTools 2.37.3

Expected results

en-us and zh-tw

Actual results

en-au and zh-cn

Code sample

import 'package:flutter/material.dart';

class LanguageHelper {
  static String getLocaleString(BuildContext context) {
    return Localizations.localeOf(context).toLanguageTag().toLowerCase();
  }
}
Text('language code: ${LanguageHelper.getLocaleString(context)}'),

Screenshots or Video

ScreenRecording_01-19-2025.15-46-22_1.mov

Logs

No response

Flutter Doctor output

➜  henhaoji git:(HMA-104) ✗ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 15.2 24C101 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.96.4)
[✓] Connected device (5 available)
[✓] Network resources

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    in triagePresently being triaged by the triage teamwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions