Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,14 @@ class Locale {
return true;
return other is Locale
&& other.languageCode == languageCode
&& other.scriptCode == scriptCode
&& other.countryCode == countryCode;
&& other.scriptCode == scriptCode // scriptCode cannot be ''
&& (other.countryCode == countryCode // Treat '' as equal to null.
|| other.countryCode != null && other.countryCode.isEmpty && countryCode == null
|| countryCode != null && countryCode.isEmpty && other.countryCode == null);
}

@override
int get hashCode => hashValues(languageCode, scriptCode, countryCode);
int get hashCode => hashValues(languageCode, scriptCode, countryCode == '' ? null : countryCode);

static Locale _cachedLocale;
static String _cachedLocaleString;
Expand Down
12 changes: 10 additions & 2 deletions testing/dart/locale_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ void main() {
expect(const Locale('en').toLanguageTag(), 'en');
expect(const Locale('en'), const Locale('en', $null));
expect(const Locale('en').hashCode, const Locale('en', $null).hashCode);
expect(const Locale('en'), isNot(const Locale('en', '')));
expect(const Locale('en').hashCode, isNot(const Locale('en', '').hashCode));
expect(const Locale('en', 'US').toLanguageTag(), 'en-US');
expect(const Locale('en', 'US').toString(), 'en_US');
expect(const Locale('iw').toLanguageTag(), 'he');
Expand Down Expand Up @@ -52,6 +50,16 @@ void main() {
isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn')));
expect(const Locale.fromSubtags(languageCode: 'en').hashCode,
isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode));

expect(const Locale('en', ''), const Locale('en'));
expect(const Locale('en'), const Locale('en', ''));
expect(const Locale('en'), const Locale('en'));
expect(const Locale('en', ''), const Locale('en', ''));

expect(const Locale('en', ''), isNot(const Locale('en', 'GB')));
expect(const Locale('en'), isNot(const Locale('en', 'GB')));
expect(const Locale('en', 'GB'), isNot(const Locale('en', '')));
expect(const Locale('en', 'GB'), isNot(const Locale('en')));
});

test('Locale toString does not include separator for \'\'', () {
Expand Down