split method

List<ArbPartDto> split(
  1. String locale
)

Implementation

List<ArbPartDto> split(String locale) {
  if (!_store.keys.contains(locale)) {
    throw ArbImportException('Invalid main locale $locale');
  }

  final result = <ArbPartDto>[];
  final mainLocale = _store[locale] as Map;

  for (final key in mainLocale.keys) {
    final otherLocales = locales..remove(locale);

    final Map<String, String> translates = otherLocales.fold({}, (ac, id) {
      if (_store[id][key] != null) {
        ac[id] = _store[id][key]['value'];
      }

      return ac;
    });

    final part = ArbPartDto(
      name: key,
      value: mainLocale[key]['value'],
      description: mainLocale[key]['description'],
      translates: translates.keys.isNotEmpty ? translates : null,
      placeholdersRaw: mainLocale[key]['placeholders'],
    );
    result.add(part);
  }

  return result;
}