Permalink
Browse files

bug: Browser didn't show the right language if Browser-Language was j…

…ust English
  • Loading branch information...
MikeMitterer committed Sep 15, 2018
1 parent 23f6700 commit a05d0f21702ec26b54ec356623ce65ef44dfad52
Showing with 10 additions and 7 deletions.
  1. +6 −6 samples/browser/lib/_l10n/messages_all.dart
  2. +4 −1 samples/browser/web/main.dart
@@ -27,17 +27,18 @@ MessageLookupByLibrary _findExact(localeName) {
/// User programs should call this before using [localeName] for messages.
Future<bool> initializeMessages(String localeName) async {
var availableLocale = Intl.verifiedLocale(
localeName,
(locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
var availableLocale = Intl.verifiedLocale( localeName,
(locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
if (availableLocale == null) {
return new Future.value(false);
}
var lib = _deferredLibraries[availableLocale];
await (lib == null ? new Future.value(false) : lib());
initializeInternalMessageLookup(() => new CompositeMessageLookup());
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
return new Future.value(true);
}
@@ -50,8 +51,7 @@ bool _messagesExistFor(String locale) {
}
MessageLookupByLibrary _findGeneratedMessagesFor(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);
}
@@ -13,10 +13,13 @@ Future main() async {
final String locale = await findSystemLocale();
final String shortLocale = Intl.shortLocale(Uri.base.queryParameters['lang'] ?? locale);
// Important - otherwise the Browser doesn't show the right language!
Intl.systemLocale = shortLocale;
// Avoids error message:
// LocaleDataException: Locale data has not been initialized,
// call initializeDateFormatting(<locale>).
await initializeDateFormatting(locale);
await initializeDateFormatting(shortLocale);
// Initialize translation-table
await initializeMessages(shortLocale);

0 comments on commit a05d0f2

Please sign in to comment.