generateTranslationMap function

String generateTranslationMap(
  1. I18nConfig config,
  2. List<I18nData> translations
)

Implementation

String generateTranslationMap(
  I18nConfig config,
  List<I18nData> translations,
) {
  final buffer = StringBuffer();

  if (config.outputFormat == OutputFormat.multipleFiles) {
    // this is a part file
    buffer.writeln('part of \'${config.baseName}.g.dart\';');
    buffer.writeln();
  }

  buffer.writeln('/// Flat map(s) containing all translations.');
  buffer.writeln(
      '/// Only for edge cases! For simple maps, use the map function of this library.');

  for (I18nData localeData in translations) {
    final language = localeData.locale.language;

    buffer.writeln();
    buffer.writeln(
        'extension on ${getClassNameRoot(baseName: config.baseName, locale: localeData.locale, visibility: config.translationClassVisibility)} {');
    buffer.writeln('\tMap<String, dynamic> _buildFlatMap() {');

    buffer.writeln('\t\treturn <String, dynamic>{');
    _generateTranslationMapRecursive(
      buffer: buffer,
      curr: localeData.root,
      config: config,
      language: language,
    );
    buffer.writeln('\t\t};');
    buffer.writeln('\t}');
    buffer.writeln('}');
  }

  return buffer.toString();
}