createTKeyFileFromMap function

String createTKeyFileFromMap(
  1. JsonMap map, {
  2. bool save = false,
  3. bool includeToString = true,
})

Generates the TKeys file from the map.

Implementation

String createTKeyFileFromMap(
  JsonMap map, {
  bool save = false,
  bool includeToString = true,
}) {
  var className = config.dartTKeysClassname; //'TKeys'
  changedWords.clear();
  _buildTKeyMap(
    map: map,
    key: className,
    path: '',
    toString: includeToString,
  );
  if (changedWords.isNotEmpty) {
    print(
      'These following keys have been changed with a prefix ${cyan("t + key")} because they are reserved words:',
    );
    for (var e in changedWords) {
      print('- $e > t$e');
    }
  }
  final fileContent =
      '// ignore_for_file: lines_longer_than_80_chars\n\n ${_translateKeyClasses.join('\n\n')}';

  _translateKeyClasses.clear();
  if (save) {
    var filepath = config.dartTkeysPath;
    // var filepath = joinDir([config.outputDir, 'i18n/tkeys.dart']);
    trace('🧱 Building keys file ($className)\n - $filepath:');
    saveString(filepath, fileContent);
  }
  return fileContent;
  // trace('saving i18n keys');
  // saveString('i18n/tkeys.dart', fileContent);
}