registerCustomLanguage static method

dynamic registerCustomLanguage(
  1. String name, {
  2. String? cancelText,
  3. String? confirmText,
  4. List<String>? ampm,
  5. List<String>? months,
  6. List<String>? monthsLong,
})

注册自定义语言

Register custom language

Implementation

static registerCustomLanguage(String name,
    {String? cancelText,
    String? confirmText,
    List<String>? ampm,
    List<String>? months,
    List<String>? monthsLong}) {
  if (name.isEmpty) return;
  if (ampm != null && ampm.length != 2) {
    throw Exception('ampm array length must be 2');
  }
  if (months != null && months.length != 12) {
    throw Exception('months array length must be 12');
  }
  if (monthsLong != null && monthsLong.length != 12) {
    throw Exception('monthsLong array length must be 12');
  }
  if (!languages.contains(name)) {
    languages.add(name);
  }
  final _defaultValue = localizedValues['en']!;
  final data = {
    'cancelText': cancelText ?? _defaultValue['cancelText'] as String,
    'confirmText': cancelText ?? _defaultValue['confirmText'] as String,
    'ampm': ampm ?? _defaultValue['ampm'] as List,
  };
  if (months != null) {
    data['months'] = months;
  }
  if (monthsLong != null) {
    data['monthsLong'] = monthsLong;
  }
  localizedValues[name] = data;
}