diff --git a/I18N Commander/Processor/TranslationProcessor.cs b/I18N Commander/Processor/TranslationProcessor.cs index 7e771b6..9de7cb8 100644 --- a/I18N Commander/Processor/TranslationProcessor.cs +++ b/I18N Commander/Processor/TranslationProcessor.cs @@ -60,6 +60,54 @@ public static class TranslationProcessor var numTotalTranslations = numCultures * numTextElements; var numTextElementsTranslated = await db.Translations.CountAsync(n => !string.IsNullOrWhiteSpace(n.Text)); + if(numTextElementsTranslated == 0 && numTotalTranslations == 0) + return new ProcessorResult(100); + + if (numTotalTranslations == 0) + return new ProcessorResult(0); + + if(numTextElementsTranslated > numTotalTranslations) + return new ProcessorResult(100); + + return new ProcessorResult(numTextElementsTranslated * 100 / numTotalTranslations); + } + + public static async Task> CalculateTranslationProgress(Section section) + { + await using var db = ProcessorMeta.ServiceProvider.GetRequiredService(); + var numCultures = (await AppSettings.GetCultureIndices()).Count; + var numTextElements = await db.TextElements.CountAsync(n => n.Section == section); + var numTotalTranslations = numCultures * numTextElements; + var numTextElementsTranslated = await db.Translations.CountAsync(n => !string.IsNullOrWhiteSpace(n.Text) && n.TextElement.Section == section); + + if(numTextElementsTranslated == 0 && numTotalTranslations == 0) + return new ProcessorResult(100); + + if (numTotalTranslations == 0) + return new ProcessorResult(0); + + if(numTextElementsTranslated > numTotalTranslations) + return new ProcessorResult(100); + + return new ProcessorResult(numTextElementsTranslated * 100 / numTotalTranslations); + } + + public static async Task> CalculateTranslationProgress(TextElement textElement) + { + await using var db = ProcessorMeta.ServiceProvider.GetRequiredService(); + var numCultures = (await AppSettings.GetCultureIndices()).Count; + var numTotalTranslations = numCultures; + var numTextElementsTranslated = await db.Translations.CountAsync(n => !string.IsNullOrWhiteSpace(n.Text) && n.TextElement == textElement); + + if(numTextElementsTranslated == 0 && numTotalTranslations == 0) + return new ProcessorResult(100); + + if (numTotalTranslations == 0) + return new ProcessorResult(0); + + if(numTextElementsTranslated > numTotalTranslations) + return new ProcessorResult(100); + return new ProcessorResult(numTextElementsTranslated * 100 / numTotalTranslations); } } \ No newline at end of file