Skip to content

Commit

Permalink
Merge pull request #783 from JamesMcIntosh:main
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 603322548
  • Loading branch information
copybara-github committed Feb 1, 2024
2 parents 5dd5d68 + a87d794 commit fadcbfd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkgs/intl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## 0.20.0-wip
* Fix caching of messages in CompositeMessageLookup
* Type `numberFormatSymbols` as a `Map<String, NumberSymbols>`.
* Type `dateTimeSymbolMap` as a `Map<String, DateSymbols>`.
* Add example for pub.dev.
Expand Down
4 changes: 2 additions & 2 deletions pkgs/intl/lib/message_lookup_by_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class CompositeMessageLookup implements MessageLookup {
if (newLocale != null) {
availableMessages[localeName] = newLocale;
availableMessages[canonical] = newLocale;
// If there was already a failed lookup for [newLocale], null the cache.
if (_lastLocale == newLocale) {
// If there was already a failed lookup for [localeName], null the cache.
if (_lastLocale == localeName) {
_lastLocale = null;
_lastLookup = null;
}
Expand Down
37 changes: 37 additions & 0 deletions pkgs/intl/test/message_lookup_by_library.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2012, 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.

library message_lookup_by_library_test;

import 'package:intl/message_lookup_by_library.dart';
import 'package:test/test.dart';

void main() {
test('Resolves message successfully after unsuccessful lookup', () {
final CompositeMessageLookup lookup = CompositeMessageLookup();
final lookupMessage =
lookup.lookupMessage('Hello', 'pt', 'greeting', null, null);
expect(lookupMessage, 'Hello');

lookup.addLocale(
'pt',
(locale) =>
TestMessageLookupByLibrary('pt', {'greeting': () => 'Bom dia'}),
);

final lookupMessage2 =
lookup.lookupMessage('Hello', 'pt', 'greeting', null, null);
expect(lookupMessage2, 'Bom dia');
});
}

class TestMessageLookupByLibrary extends MessageLookupByLibrary {
@override
final Map<String, dynamic> messages;

@override
final String localeName;

TestMessageLookupByLibrary(this.localeName, this.messages);
}

0 comments on commit fadcbfd

Please sign in to comment.