Skip to content

Commit fadcbfd

Browse files
Merge pull request #783 from JamesMcIntosh:main
PiperOrigin-RevId: 603322548
2 parents 5dd5d68 + a87d794 commit fadcbfd

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

pkgs/intl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## 0.20.0-wip
2+
* Fix caching of messages in CompositeMessageLookup
23
* Type `numberFormatSymbols` as a `Map<String, NumberSymbols>`.
34
* Type `dateTimeSymbolMap` as a `Map<String, DateSymbols>`.
45
* Add example for pub.dev.

pkgs/intl/lib/message_lookup_by_library.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class CompositeMessageLookup implements MessageLookup {
7575
if (newLocale != null) {
7676
availableMessages[localeName] = newLocale;
7777
availableMessages[canonical] = newLocale;
78-
// If there was already a failed lookup for [newLocale], null the cache.
79-
if (_lastLocale == newLocale) {
78+
// If there was already a failed lookup for [localeName], null the cache.
79+
if (_lastLocale == localeName) {
8080
_lastLocale = null;
8181
_lastLookup = null;
8282
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
library message_lookup_by_library_test;
6+
7+
import 'package:intl/message_lookup_by_library.dart';
8+
import 'package:test/test.dart';
9+
10+
void main() {
11+
test('Resolves message successfully after unsuccessful lookup', () {
12+
final CompositeMessageLookup lookup = CompositeMessageLookup();
13+
final lookupMessage =
14+
lookup.lookupMessage('Hello', 'pt', 'greeting', null, null);
15+
expect(lookupMessage, 'Hello');
16+
17+
lookup.addLocale(
18+
'pt',
19+
(locale) =>
20+
TestMessageLookupByLibrary('pt', {'greeting': () => 'Bom dia'}),
21+
);
22+
23+
final lookupMessage2 =
24+
lookup.lookupMessage('Hello', 'pt', 'greeting', null, null);
25+
expect(lookupMessage2, 'Bom dia');
26+
});
27+
}
28+
29+
class TestMessageLookupByLibrary extends MessageLookupByLibrary {
30+
@override
31+
final Map<String, dynamic> messages;
32+
33+
@override
34+
final String localeName;
35+
36+
TestMessageLookupByLibrary(this.localeName, this.messages);
37+
}

0 commit comments

Comments
 (0)