date_localizations.dart 1.11 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:intl/date_symbol_data_custom.dart' as date_symbol_data_custom;
6 7
import 'package:intl/date_symbols.dart' as intl;

8 9 10 11 12
import '../l10n/generated_date_localizations.dart' as date_localizations;

/// Tracks if date i18n data has been loaded.
bool _dateIntlDataInitialized = false;

13
/// Loads i18n data for dates if it hasn't been loaded yet.
14
///
15 16
/// Only the first invocation of this function loads the data. Subsequent
/// invocations have no effect.
17 18
void loadDateIntlDataIfNotLoaded() {
  if (!_dateIntlDataInitialized) {
19
    date_localizations.dateSymbols
20
      .forEach((String locale, intl.DateSymbols symbols) {
21 22 23 24 25 26 27 28
        // Perform initialization.
        assert(date_localizations.datePatterns.containsKey(locale));
        date_symbol_data_custom.initializeDateFormattingCustom(
          locale: locale,
          symbols: symbols,
          patterns: date_localizations.datePatterns[locale],
        );
      });
29 30
    _dateIntlDataInitialized = true;
  }
Dan Field's avatar
Dan Field committed
31
}