Skip to content

Commit

Permalink
Fix resetting of failed locale lookup when successfully resolving loc…
Browse files Browse the repository at this point in the history
…ale in composite message lookup
  • Loading branch information
JamesMcIntosh committed Jan 29, 2024
1 parent 316929f commit ae677c8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
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
31 changes: 31 additions & 0 deletions pkgs/intl/test/message_lookup_by_library.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 ae677c8

Please sign in to comment.