Content-Length: 367421 | pFad | https://github.com/flutter/flutter/issues/138609

79 Error when generating pt_BR localizations. · Issue #138609 · flutter/flutter · GitHub
Skip to content

Error when generating pt_BR localizations. #138609

@ikso95

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!

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 onteam-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









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/flutter/flutter/issues/138609

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy