diff --git a/pkgs/intl_translation/CHANGELOG.md b/pkgs/intl_translation/CHANGELOG.md index a20ad7d2d..8d6d71d54 100644 --- a/pkgs/intl_translation/CHANGELOG.md +++ b/pkgs/intl_translation/CHANGELOG.md @@ -1,6 +1,10 @@ +## 0.21.0-wip + * BREAKING CHANGE: Update `dart_style` to `^3.0.0` + * Allow analyzer `>=6.3.0 <8.0.0` + ## 0.20.1 * Add topics to `pubspec.yaml` - * Update to `dart_style `2.3.7`. `bin/make_examples_const.dart` and + * Update to `dart_style` `2.3.7`. `bin/make_examples_const.dart` and `rewrite_intl_messages.dart` will now look for a surrounding `.dart_tool/package_config.json` file to infer the language version of the files updated by the script. diff --git a/pkgs/intl_translation/lib/src/messages/constant_evaluator.dart b/pkgs/intl_translation/lib/src/messages/constant_evaluator.dart new file mode 100644 index 000000000..11cbeaac2 --- /dev/null +++ b/pkgs/intl_translation/lib/src/messages/constant_evaluator.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:analyzer/dart/ast/ast.dart'; + +/// Needed to wrap `null` as a valid constant value +class Constant { + final T value; + + Constant(this.value); + + static Constant? nullable(T? o) => + o == null ? null : Constant(o); +} + +Constant? evaluate(Expression expression) { + return switch (expression) { + AdjacentStrings() => Constant.nullable(evaluateConstString(expression)), + SimpleStringLiteral() => Constant(expression.value), + IntegerLiteral() => Constant(expression.value), + DoubleLiteral() => Constant(expression.value), + BooleanLiteral() => Constant(expression.value), + NullLiteral() => Constant(null), + SetOrMapLiteral() => evaluateConstStringMap(expression), + _ => null, + }; +} + +String? evaluateConstString(Expression expression) => switch (expression) { + SimpleStringLiteral() => expression.value, + AdjacentStrings() => _checkChildren(expression.strings)?.join(), + _ => null, + }; + +Iterable? _checkChildren(Iterable strings) { + final constExpressions = strings.map( + (string) => evaluateConstString(string), + ); + return constExpressions.any( + (string) => string == null, + ) + ? null + : constExpressions.whereType(); +} + +Constant? evaluateConstStringMap(SetOrMapLiteral map) { + if (!map.isConst) { + return null; + } + if (map.elements.any( + (element) => element is! MapLiteralEntry, + )) { + return null; + } + final evaluatedEntries = map.elements.whereType().map( + (literalEntry) => + (evaluate(literalEntry.key), evaluate(literalEntry.value)), + ); + if (evaluatedEntries + .any((element) => element.$1 == null || element.$2 == null)) { + return null; + } + var extractedValues = evaluatedEntries.map( + (literalEntry) => MapEntry(literalEntry.$1!.value, literalEntry.$2!.value), + ); + if (extractedValues.any((element) => element.key is! String)) { + return null; + } + return Constant(Map.fromEntries(extractedValues.map( + (e) => MapEntry(e.key as String, e.value), + ))); +} diff --git a/pkgs/intl_translation/lib/src/messages/main_message.dart b/pkgs/intl_translation/lib/src/messages/main_message.dart index 9943fde1e..26ff54f19 100644 --- a/pkgs/intl_translation/lib/src/messages/main_message.dart +++ b/pkgs/intl_translation/lib/src/messages/main_message.dart @@ -33,7 +33,7 @@ class MainMessage extends ComplexMessage { /// Verify that this looks like a correct Intl.message invocation. static void checkValidity( MethodInvocation node, - List arguments, + List arguments, String? outerName, List outerArgs, { bool nameAndArgsGenerated = false, diff --git a/pkgs/intl_translation/lib/src/messages/message.dart b/pkgs/intl_translation/lib/src/messages/message.dart index e66bdf342..18ca19877 100644 --- a/pkgs/intl_translation/lib/src/messages/message.dart +++ b/pkgs/intl_translation/lib/src/messages/message.dart @@ -35,11 +35,10 @@ library intl_message; import 'dart:convert'; import 'package:analyzer/dart/ast/ast.dart'; -// ignore: implementation_imports -import 'package:analyzer/src/dart/ast/constant_evaluator.dart'; import 'complex_message.dart'; import 'composite_message.dart'; +import 'constant_evaluator.dart'; import 'literal_string_message.dart'; import 'message_extraction_exception.dart'; import 'variable_substitution_message.dart'; @@ -75,26 +74,6 @@ abstract class Message { /// The name of the top-level [MainMessage]. String get name => parent == null ? '' : parent!.name; - static final _evaluator = ConstantEvaluator(); - - static String? _evaluateAsString(expression) { - var result = expression.accept(_evaluator); - if (result == ConstantEvaluator.NOT_A_CONSTANT || result is! String) { - return null; - } else { - return result; - } - } - - static Map? _evaluateAsMap(Expression expression) { - var result = expression.accept(_evaluator); - if (result == ConstantEvaluator.NOT_A_CONSTANT || result is! Map) { - return null; - } else { - return result; - } - } - /// Verify that the args argument matches the method parameters and /// isn't, e.g. passing string names instead of the argument values. static bool checkArgs(NamedExpression? args, List parameterNames) { @@ -141,7 +120,7 @@ abstract class Message { /// for messages with parameters. static void checkValidity( MethodInvocation node, - List arguments, + List arguments, String? outerName, List outerArgs, { bool nameAndArgsGenerated = false, @@ -165,7 +144,7 @@ abstract class Message { ' e.g. args: $parameterNames'); } - var nameNamedExps = arguments + final nameNamedExps = arguments .whereType() .where((arg) => arg.name.label.name == 'name') .map((e) => e.expression); @@ -177,7 +156,7 @@ abstract class Message { if (nameNamedExps.isEmpty) { if (!hasParameters) { // No name supplied, no parameters. Use the message as the name. - var name = _evaluateAsString(arguments[0]); + var name = evaluateConstString(arguments[0]); messageName = name; outerName = name; } else { @@ -195,7 +174,7 @@ abstract class Message { } } else { // Name argument is supplied, use it. - var name = _evaluateAsString(nameNamedExps.first); + var name = evaluateConstString(nameNamedExps.first); messageName = name; givenName = name; } @@ -227,7 +206,7 @@ abstract class Message { .map((each) => each.expression) .toList(); for (var arg in values) { - if (_evaluateAsString(arg) == null) { + if (evaluateConstString(arg) == null) { throw MessageExtractionException( 'Intl.message arguments must be string literals: $arg'); } @@ -245,8 +224,7 @@ abstract class Message { if (examples.isNotEmpty) { var example = examples.first; if (example is SetOrMapLiteral) { - var map = _evaluateAsMap(example); - if (map == null) { + if (evaluateConstStringMap(example) == null) { throw MessageExtractionException( 'Examples must be a const Map literal.'); } else if (example.constKeyword == null) { diff --git a/pkgs/intl_translation/lib/visitors/message_finding_visitor.dart b/pkgs/intl_translation/lib/visitors/message_finding_visitor.dart index 1326126b1..5280ca5fa 100644 --- a/pkgs/intl_translation/lib/visitors/message_finding_visitor.dart +++ b/pkgs/intl_translation/lib/visitors/message_finding_visitor.dart @@ -4,10 +4,9 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/ast/visitor.dart'; -// ignore: implementation_imports -import 'package:analyzer/src/dart/ast/constant_evaluator.dart'; import '../extract_messages.dart'; +import '../src/messages/constant_evaluator.dart'; import '../src/messages/main_message.dart'; import '../src/messages/message.dart'; import '../src/messages/message_extraction_exception.dart'; @@ -288,10 +287,8 @@ class MessageFindingVisitor extends GeneralizingAstVisitor { for (var namedExpr in arguments.whereType()) { var name = namedExpr.name.label.name; var exp = namedExpr.expression; - var basicValue = exp.accept(ConstantEvaluator()); - var value = basicValue == ConstantEvaluator.NOT_A_CONSTANT - ? exp.toString() - : basicValue; + var constant = evaluate(exp); + var value = constant == null ? exp.toString() : constant.value; setAttribute(message, name, value); } // We only rewrite messages with parameters, otherwise we use the literal diff --git a/pkgs/intl_translation/pubspec.yaml b/pkgs/intl_translation/pubspec.yaml index dfa3bc531..d457091b8 100644 --- a/pkgs/intl_translation/pubspec.yaml +++ b/pkgs/intl_translation/pubspec.yaml @@ -1,5 +1,5 @@ name: intl_translation -version: 0.20.1 +version: 0.21.0-wip description: >- Contains code to deal with internationalized/localized messages, date and number formatting and parsing, bi-directional text, and @@ -15,9 +15,9 @@ environment: sdk: ^3.0.0 dependencies: - analyzer: ^6.3.0 + analyzer: ">=6.3.0 <8.0.0" args: ^2.0.0 - dart_style: ^2.0.0 + dart_style: ^3.0.0 intl: '>=0.19.0 <0.21.0' package_config: ^2.1.0 path: ^1.0.0 diff --git a/pkgs/intl_translation/test/constant_evaluator_test.dart b/pkgs/intl_translation/test/constant_evaluator_test.dart new file mode 100644 index 000000000..eb3d87fec --- /dev/null +++ b/pkgs/intl_translation/test/constant_evaluator_test.dart @@ -0,0 +1,145 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:analyzer/dart/analysis/features.dart'; +import 'package:analyzer/dart/analysis/utilities.dart'; +import 'package:analyzer/dart/ast/ast.dart'; +import 'package:intl_translation/src/messages/constant_evaluator.dart'; +import 'package:test/test.dart'; + +void main() { + group('Constant class', () { + test('should wrap values including null', () { + final stringConstant = Constant('test'); + expect(stringConstant.value, 'test'); + + final nullConstant = Constant(null); + expect(nullConstant.value, isNull); + }); + + test('nullable should handle null and non-null values', () { + expect(Constant.nullable(null), isNull); + + final result = Constant.nullable('test'); + expect(result!.value, 'test'); + }); + }); + + group('evaluate function', () { + test('should evaluate all basic literal types', () { + expect( + evaluate(_parseExpression('"hello"') as SimpleStringLiteral)!.value, + 'hello'); + expect(evaluate(_parseExpression('42') as IntegerLiteral)!.value, 42); + expect(evaluate(_parseExpression('3.14') as DoubleLiteral)!.value, 3.14); + expect(evaluate(_parseExpression('true') as BooleanLiteral)!.value, true); + expect(evaluate(_parseExpression('null') as NullLiteral)!.value, isNull); + }); + + test('should evaluate AdjacentStrings', () { + final result = + evaluate(_parseExpression('"hello " "world"') as AdjacentStrings); + expect(result!.value, 'hello world'); + }); + + test('should evaluate const maps', () { + final result = evaluate( + _parseExpression('const {"key": "value", "num": 42}') + as SetOrMapLiteral); + final map = result!.value as Map; + expect(map['key'], 'value'); + expect(map['num'], 42); + }); + + test('should return null for unsupported expressions', () { + expect(evaluate(_parseExpression('someVariable') as SimpleIdentifier), + isNull); + expect(evaluate(_parseExpression('someFunction()') as MethodInvocation), + isNull); + }); + }); + + group('evaluateConstString function', () { + test('should evaluate string literals and adjacent strings', () { + expect( + evaluateConstString( + _parseExpression('"hello"') as SimpleStringLiteral), + 'hello'); + expect( + evaluateConstString( + _parseExpression('"hello " "world"') as AdjacentStrings), + 'hello world'); + }); + + test('should return null for non-string expressions', () { + expect(evaluateConstString(_parseExpression('42') as IntegerLiteral), + isNull); + expect( + evaluateConstString( + _parseExpression(r'"hello ${variable}"') as StringInterpolation), + isNull); + }); + }); + + group('evaluateConstStringMap function', () { + test('should evaluate const maps with string keys', () { + final result = evaluateConstStringMap(_parseExpression( + 'const {"str": "value", "num": 42, "bool": true, "nil": null}') + as SetOrMapLiteral); + final map = result!.value as Map; + expect(map['str'], 'value'); + expect(map['num'], 42); + expect(map['bool'], true); + expect(map['nil'], isNull); + }); + + test('should handle nested maps and adjacent strings', () { + final result = evaluateConstStringMap( + _parseExpression('const {"outer": const {"inner": "hello " "world"}}') + as SetOrMapLiteral); + final outerMap = result!.value as Map; + final innerMap = outerMap['outer'] as Map; + expect(innerMap['inner'], 'hello world'); + }); + + test('should return null for invalid cases', () { + // Non-const map + expect( + evaluateConstStringMap( + _parseExpression('{"key": "value"}') as SetOrMapLiteral), + isNull); + + // Const set (not map) + expect( + evaluateConstStringMap( + _parseExpression('const {"item1", "item2"}') as SetOrMapLiteral), + isNull); + + // Non-string keys + expect( + evaluateConstStringMap( + _parseExpression('const {42: "value"}') as SetOrMapLiteral), + isNull); + + // Non-evaluable values + expect( + evaluateConstStringMap(_parseExpression('const {"key": someVariable}') + as SetOrMapLiteral), + isNull); + }); + }); +} + +/// Helper function to parse a single expression from a string +Expression _parseExpression(String code) { + final unit = parseString( + content: 'var x = $code;', + featureSet: FeatureSet.latestLanguageVersion(), + ).unit; + + final variableDeclaration = + unit.declarations.first as TopLevelVariableDeclaration; + final variable = variableDeclaration.variables.variables.first; + return variable.initializer!; +} diff --git a/pkgs/intl_translation/test/generate_localized/code_map_messages_all.dart b/pkgs/intl_translation/test/generate_localized/code_map_messages_all.dart index a4e4df4b4..a82c78c70 100644 --- a/pkgs/intl_translation/test/generate_localized/code_map_messages_all.dart +++ b/pkgs/intl_translation/test/generate_localized/code_map_messages_all.dart @@ -1,9 +1,12 @@ // DO NOT EDIT. This is code generated via package:intl/generate_localized.dart // This is a library that looks up messages for specific locales by // delegating to the appropriate library. +// @dart=2.12 import 'package:intl/intl.dart'; -export 'code_map_messages_all_locales.dart' show initializeMessages; +export 'code_map_messages_all_locales.dart' + show initializeMessages; + /// Turn the JSON template into a string. /// @@ -26,39 +29,44 @@ String? evaluateJsonTemplate(dynamic input, List args) { var template = input as List; var messageName = template.first; if (messageName == 'Intl.plural') { - var howMany = args[template[1] as int] as num; - return evaluateJsonTemplate( - Intl.pluralLogic(howMany, - zero: template[2], - one: template[3], - two: template[4], - few: template[5], - many: template[6], - other: template[7]), - args); - } - if (messageName == 'Intl.gender') { - var gender = args[template[1] as int] as String; - return evaluateJsonTemplate( - Intl.genderLogic(gender, - female: template[2], male: template[3], other: template[4]), - args); - } - if (messageName == 'Intl.select') { - var select = args[template[1] as int] as Object; - var choices = template[2] as Map; - return evaluateJsonTemplate(Intl.selectLogic(select, choices), args); - } + var howMany = args[template[1] as int] as num; + return evaluateJsonTemplate( + Intl.pluralLogic( + howMany, + zero: template[2], + one: template[3], + two: template[4], + few: template[5], + many: template[6], + other: template[7]), + args); + } + if (messageName == 'Intl.gender') { + var gender = args[template[1] as int] as String; + return evaluateJsonTemplate( + Intl.genderLogic( + gender, + female: template[2], + male: template[3], + other: template[4]), + args); + } + if (messageName == 'Intl.select') { + var select = args[template[1] as int] as Object; + var choices = template[2] as Map; + return evaluateJsonTemplate(Intl.selectLogic(select, choices), args); + } - // If we get this far, then we are a basic interpolation, just strings and - // ints. - var output = StringBuffer(); - for (var entry in template) { - if (entry is int) { - output.write('${args[entry]}'); - } else { - output.write('$entry'); - } + // If we get this far, then we are a basic interpolation, just strings and + // ints. + var output = StringBuffer(); + for (var entry in template) { + if (entry is int) { + output.write('${args[entry]}'); + } else { + output.write('$entry'); + } + } + return output.toString(); } - return output.toString(); -} + diff --git a/pkgs/intl_translation/test/generate_localized/code_map_messages_all_locales.dart b/pkgs/intl_translation/test/generate_localized/code_map_messages_all_locales.dart index 2cbc47ed9..f129b600b 100644 --- a/pkgs/intl_translation/test/generate_localized/code_map_messages_all_locales.dart +++ b/pkgs/intl_translation/test/generate_localized/code_map_messages_all_locales.dart @@ -1,7 +1,7 @@ // DO NOT EDIT. This is code generated via package:intl/generate_localized.dart // This is a library that looks up messages for specific locales by // delegating to the appropriate library. - +// @dart=2.12 // Ignore issues from commonly used lints in this file. // ignore_for_file:implementation_imports, file_names // ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering @@ -32,8 +32,9 @@ MessageLookupByLibrary? _findExact(String localeName) { /// User programs should call this before using [localeName] for messages. Future initializeMessages(String? localeName) async { var availableLocale = Intl.verifiedLocale( - localeName, (locale) => _deferredLibraries[locale] != null, - onFailure: (_) => null); + localeName, + (locale) => _deferredLibraries[locale] != null, + onFailure: (_) => null); if (availableLocale == null) { return Future.value(false); } @@ -53,8 +54,8 @@ bool _messagesExistFor(String locale) { } MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) { - var actualLocale = - Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null); + var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, + onFailure: (_) => null); if (actualLocale == null) return null; return _findExact(actualLocale); } diff --git a/pkgs/intl_translation/test/generate_localized/code_map_messages_fr.dart b/pkgs/intl_translation/test/generate_localized/code_map_messages_fr.dart index 1dc09d212..b8bd04cca 100644 --- a/pkgs/intl_translation/test/generate_localized/code_map_messages_fr.dart +++ b/pkgs/intl_translation/test/generate_localized/code_map_messages_fr.dart @@ -2,7 +2,7 @@ // This is a library that provides messages for a fr locale. All the // messages from the main program should be duplicated here with the same // function name. - +// @dart=2.12 // Ignore issues from commonly used lints in this file. // ignore_for_file:unnecessary_brace_in_string_interps // ignore_for_file:prefer_single_quotes,comment_references, directives_ordering @@ -19,18 +19,18 @@ import 'dart:collection'; final messages = MessageLookup(); -typedef String? MessageIfAbsent(String? messageStr, List? args); +typedef String? MessageIfAbsent( + String? messageStr, List? args); class MessageLookup extends MessageLookupByLibrary { @override String get localeName => 'fr'; + String? evaluateMessage(dynamic translation, List args) { return evaluateJsonTemplate(translation, args); } - Map get messages => _constMessages; - static const _constMessages = { - "Hello from application": "Bonjour de l'application" - }; -} + static const _constMessages = {"Hello from application":["Bonjour de l'application"]}; + +} \ No newline at end of file diff --git a/pkgs/intl_translation/test/two_components/app_messages_all.dart b/pkgs/intl_translation/test/two_components/app_messages_all.dart index ca710f225..a6905f88a 100644 --- a/pkgs/intl_translation/test/two_components/app_messages_all.dart +++ b/pkgs/intl_translation/test/two_components/app_messages_all.dart @@ -1,5 +1,7 @@ // DO NOT EDIT. This is code generated via package:intl/generate_localized.dart // This is a library that looks up messages for specific locales by // delegating to the appropriate library. +// @dart=2.12 +export 'app_messages_all_locales.dart' + show initializeMessages; -export 'app_messages_all_locales.dart' show initializeMessages; diff --git a/pkgs/intl_translation/test/two_components/app_messages_all_locales.dart b/pkgs/intl_translation/test/two_components/app_messages_all_locales.dart index 793c9d3db..8d259c43c 100644 --- a/pkgs/intl_translation/test/two_components/app_messages_all_locales.dart +++ b/pkgs/intl_translation/test/two_components/app_messages_all_locales.dart @@ -1,7 +1,7 @@ // DO NOT EDIT. This is code generated via package:intl/generate_localized.dart // This is a library that looks up messages for specific locales by // delegating to the appropriate library. - +// @dart=2.12 // Ignore issues from commonly used lints in this file. // ignore_for_file:implementation_imports, file_names // ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering @@ -32,8 +32,9 @@ MessageLookupByLibrary? _findExact(String localeName) { /// User programs should call this before using [localeName] for messages. Future initializeMessages(String? localeName) async { var availableLocale = Intl.verifiedLocale( - localeName, (locale) => _deferredLibraries[locale] != null, - onFailure: (_) => null); + localeName, + (locale) => _deferredLibraries[locale] != null, + onFailure: (_) => null); if (availableLocale == null) { return Future.value(false); } @@ -53,8 +54,8 @@ bool _messagesExistFor(String locale) { } MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) { - var actualLocale = - Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null); + var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, + onFailure: (_) => null); if (actualLocale == null) return null; return _findExact(actualLocale); } diff --git a/pkgs/intl_translation/test/two_components/app_messages_fr.dart b/pkgs/intl_translation/test/two_components/app_messages_fr.dart index d4908b4cc..9d17ab21c 100644 --- a/pkgs/intl_translation/test/two_components/app_messages_fr.dart +++ b/pkgs/intl_translation/test/two_components/app_messages_fr.dart @@ -2,7 +2,7 @@ // This is a library that provides messages for a fr locale. All the // messages from the main program should be duplicated here with the same // function name. - +// @dart=2.12 // Ignore issues from commonly used lints in this file. // ignore_for_file:unnecessary_brace_in_string_interps // ignore_for_file:prefer_single_quotes,comment_references, directives_ordering @@ -14,18 +14,17 @@ import 'package:intl/message_lookup_by_library.dart'; final messages = MessageLookup(); -typedef String? MessageIfAbsent(String? messageStr, List? args); +typedef String? MessageIfAbsent( + String? messageStr, List? args); class MessageLookup extends MessageLookupByLibrary { @override String get localeName => 'fr'; @override - final Map messages = - _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static Map _notInlinedMessages(_) => { - 'Hello from application': - MessageLookupByLibrary.simpleMessage('Bonjour de l\'application') - }; + 'Hello from application': MessageLookupByLibrary.simpleMessage('Bonjour de l\'application') + }; } diff --git a/pkgs/intl_translation/test/two_components/component_messages_all.dart b/pkgs/intl_translation/test/two_components/component_messages_all.dart index 77101afe5..505188af6 100644 --- a/pkgs/intl_translation/test/two_components/component_messages_all.dart +++ b/pkgs/intl_translation/test/two_components/component_messages_all.dart @@ -1,5 +1,7 @@ // DO NOT EDIT. This is code generated via package:intl/generate_localized.dart // This is a library that looks up messages for specific locales by // delegating to the appropriate library. +// @dart=2.12 +export 'component_messages_all_locales.dart' + show initializeMessages; -export 'component_messages_all_locales.dart' show initializeMessages; diff --git a/pkgs/intl_translation/test/two_components/component_messages_all_locales.dart b/pkgs/intl_translation/test/two_components/component_messages_all_locales.dart index 5b3957937..361cee748 100644 --- a/pkgs/intl_translation/test/two_components/component_messages_all_locales.dart +++ b/pkgs/intl_translation/test/two_components/component_messages_all_locales.dart @@ -1,7 +1,7 @@ // DO NOT EDIT. This is code generated via package:intl/generate_localized.dart // This is a library that looks up messages for specific locales by // delegating to the appropriate library. - +// @dart=2.12 // Ignore issues from commonly used lints in this file. // ignore_for_file:implementation_imports, file_names // ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering @@ -32,8 +32,9 @@ MessageLookupByLibrary? _findExact(String localeName) { /// User programs should call this before using [localeName] for messages. Future initializeMessages(String? localeName) async { var availableLocale = Intl.verifiedLocale( - localeName, (locale) => _deferredLibraries[locale] != null, - onFailure: (_) => null); + localeName, + (locale) => _deferredLibraries[locale] != null, + onFailure: (_) => null); if (availableLocale == null) { return Future.value(false); } @@ -53,8 +54,8 @@ bool _messagesExistFor(String locale) { } MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) { - var actualLocale = - Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null); + var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, + onFailure: (_) => null); if (actualLocale == null) return null; return _findExact(actualLocale); } diff --git a/pkgs/intl_translation/test/two_components/component_messages_fr_xyz123.dart b/pkgs/intl_translation/test/two_components/component_messages_fr_xyz123.dart index 49c186099..58d89dee4 100644 --- a/pkgs/intl_translation/test/two_components/component_messages_fr_xyz123.dart +++ b/pkgs/intl_translation/test/two_components/component_messages_fr_xyz123.dart @@ -2,7 +2,7 @@ // This is a library that provides messages for a fr_xyz123 locale. All the // messages from the main program should be duplicated here with the same // function name. - +// @dart=2.12 // Ignore issues from commonly used lints in this file. // ignore_for_file:unnecessary_brace_in_string_interps // ignore_for_file:prefer_single_quotes,comment_references, directives_ordering @@ -14,19 +14,18 @@ import 'package:intl/message_lookup_by_library.dart'; final messages = MessageLookup(); -typedef String? MessageIfAbsent(String? messageStr, List? args); +typedef String? MessageIfAbsent( + String? messageStr, List? args); class MessageLookup extends MessageLookupByLibrary { @override String get localeName => 'fr_xyz123'; @override - final Map messages = - _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static Map _notInlinedMessages(_) => { - 'Hello from component': - MessageLookupByLibrary.simpleMessage('Bonjour du composant'), - '_message2': MessageLookupByLibrary.simpleMessage('Locale explicite') - }; + 'Hello from component': MessageLookupByLibrary.simpleMessage('Bonjour du composant'), + '_message2': MessageLookupByLibrary.simpleMessage('Locale explicite') + }; }