exportAnalyticsToJson method
Exports analytics to JSON file
Implementation
Future<void> exportAnalyticsToJson(
LocalizationAnalytics analytics, String outputPath) async {
final jsonData = {
'timestamp': DateTime.now().toIso8601String(),
'project_path': projectPath,
'summary': {
'total_strings': analytics.totalStringsFound,
'localized_strings': analytics.localizedStrings,
'non_localized_strings': analytics.nonLocalizedStrings,
'coverage_percentage': analytics.coveragePercentage,
'complexity_score': analytics.complexityScore,
},
'duplicates': analytics.duplicateStrings.map((key, value) => MapEntry(
key,
value
.map((s) => {
'file': s.filePath,
'line': s.lineNumber,
'content': s.content,
})
.toList(),
)),
'unused_translations': analytics.unusedTranslations,
'files_coverage': analytics.filesCoverage.map((key, value) => MapEntry(
key,
{
'coverage_percentage': value.coveragePercentage,
'total_strings': value.totalStrings,
'non_localized_strings': value.nonLocalizedStrings,
'issues': value.issues,
},
)),
'recommendations': analytics.recommendations,
};
final file = File(outputPath);
await file.writeAsString(JsonEncoder.withIndent(' ').convert(jsonData));
if (verbose) {
print('📄 Analytics exported to: $outputPath');
}
}