From c8b5dc9b7ad6c80d525d5f14bb4271b119c02282 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Mon, 26 Sep 2022 19:24:24 +0200 Subject: [PATCH] Added method to calculate the overall translation progress --- I18N Commander/Processor/TranslationProcessor.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/I18N Commander/Processor/TranslationProcessor.cs b/I18N Commander/Processor/TranslationProcessor.cs index f2d2494..7e771b6 100644 --- a/I18N Commander/Processor/TranslationProcessor.cs +++ b/I18N Commander/Processor/TranslationProcessor.cs @@ -51,4 +51,15 @@ public static class TranslationProcessor return updateException.ToProcessorResult(); } } + + public static async Task> CalculateTranslationProgress() + { + await using var db = ProcessorMeta.ServiceProvider.GetRequiredService(); + var numCultures = (await AppSettings.GetCultureIndices()).Count; + var numTextElements = await db.TextElements.CountAsync(); + var numTotalTranslations = numCultures * numTextElements; + var numTextElementsTranslated = await db.Translations.CountAsync(n => !string.IsNullOrWhiteSpace(n.Text)); + + return new ProcessorResult(numTextElementsTranslated * 100 / numTotalTranslations); + } } \ No newline at end of file