Skip to content

Error when generating pt_BR localizations. #138609

Closed

Description

@ikso95

Is there an existing issue for this?

Steps to reproduce

With new project just add two .arg files:

pt.arb

 {
   "@@locale": "pt",
   "@@last_modified": "2023-11-17T11:23:45+01:00",
   "test": "test_PT"
 }

pt_BR.arb

{
  "@@locale": "pt_BR",
  "@@last_modified": "2023-11-17T11:23:45+01:00",
  "test": "test_PT_BR"
}

l10n.yam:

arb-dir: lib/l10n
template-arb-file: pt.arb
output-localization-file: app_localizations.dart

When trying to run flutter gen-l10n such error appears:

The locale specified in @@Locale and the arb filename do not match.
Please make sure that they match, since this prevents any confusion
with which locale to use. Otherwise, specify the locale in either the
filename of the @@Locale key only.
Current @@Locale value: pt_BR
Current filename extension: br

Because of that AppLocalizationsPtBr class is not generated.
After small investigation I fount a bug in here: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/localizations/gen_l10n_types.dart

In line: 599
if (parserResult != null && _iso639Languages.contains(parserResult.languageCode)) {
the 'BR' from 'pt_BR' is treated as 'br' - Breton Language Breton

Expected results

I would expect to create class for portuguese brasil language

Actual results

L10nException thrown when generating language class.

Exception: The locale specified in @@locale and the arb filename do not match. 
Please make sure that they match, since this prevents any confusion with which locale to use. 
Otherwise, specify the locale in either the filename of the @@locale key only. 
Current @@locale value: pt_BR 
Current filename extension: br

Code sample

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs

% flutter gen-l10n
Because l10n.yaml exists, the options defined there will be used instead.
To use the command line arguments, delete the l10n.yaml file in the Flutter project.

The locale specified in @@Locale and the arb filename do not match.
Please make sure that they match, since this prevents any confusion
with which locale to use. Otherwise, specify the locale in either the
filename of the @@Locale key only.
Current @@Locale value: pt_br
Current filename extension: br

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.1, on macOS 14.1.1 23B81 darwin-arm64, locale en-PL)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] Connected device (2 available)
[✓] Network resources

• No issues found!

Activity

  1. danagbemava-nc commented on Nov 17, 2023

    @danagbemava-nc
    Member

    Reproducible using the code snippets and steps outlined above.

    flutter doctor -v
    [✓] Flutter (Channel stable, 3.16.0, on macOS 14.0 23A344 darwin-arm64, locale en-GB)
        • Flutter version 3.16.0 on channel stable at /Users/nexus/dev/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision db7ef5bf9f (2 days ago), 2023-11-15 11:25:44 -0800
        • Engine revision 74d16627b9
        • Dart version 3.2.0
        • DevTools version 2.28.2
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc1)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0-rc1
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0)
        • Xcode at /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer
        • Build 15A240d
        • CocoaPods version 1.13.0
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.3)
        • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 76.3.4
        • Dart plugin version 232.10072.19
    
    [✓] VS Code (version 1.84.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.76.0
    
    [✓] Connected device (5 available)
        • Pixel 7 (mobile)     • 28291FDH2001SA            • android-arm64  • Android 14 (API 34)
        • Nexus (mobile)       • 00008020-001875E83A38002E • ios            • iOS 17.1.1 21B91
        • Dean’s iPad (mobile) • 00008103-000825C811E3401E • ios            • iOS 17.1 21B74
        • macOS (desktop)      • macos                     • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
        • Chrome (web)         • chrome                    • web-javascript • Google Chrome 119.0.6045.159
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    
    [!] Flutter (Channel master, 3.17.0-10.0.pre.42, on macOS 14.0 23A344 darwin-arm64, locale en-GB)
        • Flutter version 3.17.0-10.0.pre.42 on channel master at /Users/nexus/dev/sdks/flutters
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision e9de448420 (13 hours ago), 2023-11-17 02:08:13 +0100
        • Engine revision 5064aeff00
        • Dart version 3.3.0 (build 3.3.0-143.0.dev)
        • DevTools version 2.30.0-dev.4
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc1)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0-rc1
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0)
        • Xcode at /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer
        • Build 15A240d
        • CocoaPods version 1.13.0
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.3)
        • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 76.3.4
        • Dart plugin version 232.10072.19
    
    [✓] VS Code (version 1.84.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.76.0
    
    [✓] Connected device (5 available)
        • Pixel 7 (mobile)     • 28291FDH2001SA            • android-arm64  • Android 14 (API 34)
        • Nexus (mobile)       • 00008020-001875E83A38002E • ios            • iOS 17.1.1 21B91
        • Dean’s iPad (mobile) • 00008103-000825C811E3401E • ios            • iOS 17.1 21B74
        • macOS (desktop)      • macos                     • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
        • Chrome (web)         • chrome                    • web-javascript • Google Chrome 119.0.6045.159
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
    
  2. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    a: internationalizationSupporting other languages or locales. (aka i18n)
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-toolOwned by Flutter Tool team
    and removed
    in triagePresently being triaged by the triage team
    on Nov 17, 2023
  3. ikso95 commented on Apr 25, 2024

    @ikso95
    Author

    @danagbemava-nc Any updated on that bug?

  4. neoacevedo commented on Apr 29, 2024

    @neoacevedo

    It happens too with the es variant 419:

    Current @@Locale value: es-419
    Current filename extension:es_419

    But I changed the @@Locale value to es_419 and the filename too and nothing changes.

  5. added
    P2Important issues not at the top of the work list
    triaged-toolTriaged by Flutter Tool team
    on Apr 30, 2024
  6. martinsbrn commented on Dec 30, 2024

    @martinsbrn

    Same situation using the documentation: https://docs.flutter.dev/ui/accessibility-and-internationalization/internationalization

    if the pt_BR arb file has the @@Locale attribute = pt_BR we got the following message when generating files: "The locale specified in @@Locale and the arb filename do not match (Current @@Locale value: pt_BR - Current filename extension: br)"

    l10n.yaml used:

    preferred-supported-locales:
      - en
      - en_CA
      - es
      - pt
      - pt_BR
    

    Generated app_localization.dart:

    static const List<Locale> supportedLocales = <Locale>[
        Locale('en'),
        Locale('en', 'CA'),
        Locale('es'),
        Locale('pt'),
        Locale('pt', 'BR'),
        Locale('ca'), // => Generated by @@locale attribute?
        Locale('br') // => Generated by @@locale attribute?
      ];
    
    // _AppLocalizationsDelegate
      switch (locale.languageCode) { // => Will never have the languages ​​codes "ca" and "br" from locale.
        case 'en': return app_localization_en.loadLibrary().then((dynamic _) => app_localization_en.AppLocalizationsEn());
        case 'ca': return app_localization_ca.loadLibrary().then((dynamic _) => app_localization_ca.AppLocalizationsCa());
        case 'es': return app_localization_es.loadLibrary().then((dynamic _) => app_localization_es.AppLocalizationsEs());
        case 'pt': return app_localization_pt.loadLibrary().then((dynamic _) => app_localization_pt.AppLocalizationsPt());
        case 'br': return app_localization_br.loadLibrary().then((dynamic _) => app_localization_br.AppLocalizationsBr());
      }
    
  7. added
    tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.
    on Jul 11, 2025
  8. added 2 commits that reference this issue on Sep 23, 2025
    cd2bf7d
    7fc6613
  9. added a commit that references this issue on Nov 26, 2025
    8fed33a
  10. added a commit that references this issue on Dec 2, 2025
    271ab47
  11. added a commit that references this issue on Dec 10, 2025
    d6e5e35
  12. github-actions commented on Dec 11, 2025

    @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.

  13. locked as resolved and limited conversation to collaborators on Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: internationalizationSupporting other languages or locales. (aka i18n)found in release: 3.16Found to occur in 3.16found in release: 3.17Found to occur in 3.17has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-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 team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions