www/apps/resources/references/translation/ITranslationModuleService/methods/translation.ITranslationModuleService.getStatistics/page.mdx
import { TypeList } from "docs-ui"
This documentation provides a reference to the getStatistics method. This belongs to the Translation Module.
You should only use this methods when implementing complex customizations. For common cases, check out available workflows instead.
</Note>This method retrieves translation statistics for the specified entities and locales. It's useful to understand the translation coverage of different entities across various locales.
You can use this method to get insights into how many fields are translated, missing translations, and the expected number of translations based on the entities and locales provided.
const [,count] = await productModuleService.listAndCountProducts()
const [,variantCount] = await productVariantModuleService.listAndCountProductVariants()
const stats = await translationModuleService.getStatistics({
locales: ["en-US", "fr-FR"],
entities: {
product: { count }, // for example, 2 products
product_variant: { count: variantCount },
}
})
// Returns:
// {
// product: {
// expected: 20, // 2 products × 5 fields × 2 locales
// translated: 15,
// missing: 5,
// by_locale: {
// "en-US": { expected: 10, translated: 8, missing: 2 },
// "fr-FR": { expected: 10, translated: 7, missing: 3 }
// }
// }
// }
<TypeList types={[{"name":"input","type":"TranslationStatisticsInput","description":"The entities and locales to check.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"locales","type":"string[]","description":"Locales to check translations for.","optional":false,"defaultValue":"","example":"["en-US", "fr-FR"]","expandable":false,"children":[]},{"name":"entities","type":"Record<string, object>","description":"Key-value pairs of entity types and their configurations.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"count","type":"number","description":"Total number of records for the entity type.\nFor example, total number of products.\n\nThis is necessary to compute expected translation counts.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"name":"sharedContext","type":"Context","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type TManager, which is a typed parameter passed to the context to specify the type of the transactionManager.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type TManager, which is a typed parameter passed to the context to specify the type of the manager.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"string","description":"A string indicating the isolation level of the context. Possible values are READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, or SERIALIZABLE.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"boolean","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"string","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"string","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"string","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"IMessageAggregator","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"string","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"string","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"string","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"boolean","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"boolean","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"boolean","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getStatistics"/>
<TypeList types={[{"name":"Promise","type":"Promise<TranslationStatisticsOutput>","optional":false,"defaultValue":"","description":"Statistics by entity.","expandable":false,"children":[{"name":"expected","type":"number","description":"Expected total number of translated fields.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"translated","type":"number","description":"Actual number of translated fields. This doesn't count\ntranslations that are null or empty.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"missing","type":"number","description":"Number of missing translations for expected translatable\nfields.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"by_locale","type":"Record<string, [LocaleStatistics](../../../interfaces/translation.LocaleStatistics/page.mdx)>","description":"Breakdown of statistics by locale.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"expected","type":"number","description":"Expected total number of translated fields.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"translated","type":"number","description":"Actual number of translated fields. This doesn't count\ntranslations that are null or empty.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"missing","type":"number","description":"Number of missing translations for expected translatable\nfields.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getStatistics"/>