Skip to content

[Bug] Stop using Intl.defaultLocale in generated code #122

@Knupper

Description

@Knupper

Hello,

according to the newest flutter documentation and described (here)[https://github.com/flutter/website/pull/3013] the usage of Intl.defaultLocale should be avoided. We have exactly the described problem from the flutter pull request and as soon as we start the about dialog, our language is changed and our whole app is displayed in english instead of the user selected language.

As soon as i manipulate the generated L10n.dart as it is proposed inside the linked pull request, the app uses the correct language.

// GENERATED CODE - DO NOT MODIFY BY HAND
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:localizely_sdk/localizely_sdk.dart';
import 'intl/messages_all.dart';

// **************************************************************************
// Generator: Flutter Intl IDE plugin
// Made by Localizely
// **************************************************************************

// ignore_for_file: non_constant_identifier_names, lines_longer_than_80_chars
// ignore_for_file: join_return_with_assignment, prefer_final_in_for_each
// ignore_for_file: avoid_redundant_argument_values, avoid_escaping_inner_quotes

class L10n {
  L10n(this.localeName);

  final String localeName;

  static L10n? _current;

  static L10n get current {
    assert(_current != null,
        'No instance of L10n was loaded. Try to initialize the L10n delegate before accessing L10n.current.');
    return _current!;
  }

  static const AppLocalizationDelegate delegate = AppLocalizationDelegate();

  static Future<L10n> load(Locale locale) {
    final name = (locale.countryCode?.isEmpty ?? false) ? locale.languageCode : locale.toString();
    final localeName = Intl.canonicalizedLocale(name);
    if (!Localizely.hasMetadata()) {
      Localizely.setMetadata(_metadata);
    }
    return initializeMessages(localeName).then((_) {
      // instead of Intl.defaultLocale = localeName;
      final instance = L10n(localeName);
      L10n._current = instance;

      return instance;
    });
  }

it would be great if you can take a look into it and update your code generation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions