Repository: WeblateOrg/weblate

Issue:
Per-language statistics miscalculated on nested categories
### Discussed in https://github.com/WeblateOrg/weblate/discussions/11153

<div type='discussions-op-text'>

<sup>Originally posted by **vanlinh2204** March  8, 2024</sup>
The problem arises when observing the statistics in the category ipension-front-office. Here's a breakdown of the issue:

![image](https://github.com/WeblateOrg/weblate/assets/133736755/287396ee-4a0e-460e-bddb-6616f1dbc083)


Uniform Unfinished String Count: Within the ipension-front-office category, I've noticed that the unfinished string count remains consistent across 4 languages: fr, de, it, en. However, upon closer inspection, this count does not accurately reflect the number of strings requiring translation in each language. For instance, no strings appear for translation when selecting the French (fr) language, despite the reported count.

![image](https://github.com/WeblateOrg/weblate/assets/133736755/3b691dc5-b1ac-4267-9333-85f866a71a5b)


Correct Display in Sub-categories: Conversely, when navigating to the sub-category ipension-front-office/portal-service, the language tab correctly displays the number of unfinished strings, such as 40 in English (en). Further exploration into the components within ipension-front-office/portal-service, such as core-portal-service (10 unfinished in English) and first-portal-services (30 unfinished in English), indicates the accurate count of unfinished strings.

![image](https://github.com/WeblateOrg/weblate/assets/133736755/52938071-5ea4-44c0-94a3-77322e544f9b)
![image](https://github.com/WeblateOrg/weblate/assets/133736755/9c1a5c10-ae75-4412-b8ed-10ae8edfcf2f)
![image](https://github.com/WeblateOrg/weblate/assets/133736755/4dce269d-d6ef-4313-a87b-64dac6b2d601)


This inconsistency in statistic calculation poses challenges for translators and project managers relying on Weblate's data accuracy for localization efforts.

I kindly request your assistance in addressing this matter and welcome any suggestions or insights you may have regarding this issue. Additionally, if anyone has encountered similar challenges or has insights into potential solutions, please share them here.

Thank you for your attention to this matter, and I look forward to your responses.</div>


Discussion:

Resolving patch:
diff --git a/weblate/utils/stats.py b/weblate/utils/stats.py
--- a/weblate/utils/stats.py
+++ b/weblate/utils/stats.py
@@ -1184,7 +1184,10 @@ def has_review(self):
         )
 
     def get_category_objects(self):
-        return self.category.stats.get_category_objects()
+        return [
+            CategoryLanguage(category, self.language)
+            for category in self.category.stats.get_category_objects()
+        ]
 
     def get_child_objects(self):
         return self.language.translation_set.filter(
@@ -1205,7 +1208,7 @@ def get_child_objects(self):
         return self._object.component_set.only("id", "category")
 
     def get_category_objects(self):
-        return prefetch_stats(self._object.category_set.only("id", "category"))
+        return self._object.category_set.only("id", "category")
 
     def get_single_language_stats(self, language):
         return CategoryLanguageStats(CategoryLanguage(self._object, language))


Test patch: