feat(): Translation statistics (#14299)
* chore(): Translation statistics * chore(): improve statistics performances * add end point to get statistics * add tests * Create spicy-games-unite.md * feat(): add material and fix tests * feat(): add translatable api * feat(): add translatable api * fix tests * fix tests * fix tests * feedback
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Computes the count of translated fields based on the translatable fields configuration.
|
||||
* Only counts fields that are:
|
||||
* 1. In the translatableFields array for the entity type
|
||||
* 2. Have a non-null, non-empty value in the translations object
|
||||
*
|
||||
* @param translations - The translations JSON object from the translation record
|
||||
* @param translatableFields - Array of field names that are translatable for this entity type
|
||||
* @returns The count of translated fields
|
||||
*/
|
||||
export function computeTranslatedFieldCount(
|
||||
translations: Record<string, unknown> | undefined | null,
|
||||
translatableFields: string[] | undefined | null
|
||||
): number {
|
||||
if (!translations || !translatableFields?.length) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return translatableFields.filter((field) => {
|
||||
const value = translations[field]
|
||||
return value != null && value !== "" && value !== "null"
|
||||
}).length
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export const TRANSLATABLE_FIELDS_CONFIG_KEY = "translatableFieldsConfig"
|
||||
@@ -0,0 +1,9 @@
|
||||
export const PRODUCT_TRANSLATABLE_FIELDS = [
|
||||
"title",
|
||||
"description",
|
||||
"material",
|
||||
"subtitle",
|
||||
"status",
|
||||
]
|
||||
|
||||
export const PRODUCT_VARIANT_TRANSLATABLE_FIELDS = ["title", "material"]
|
||||
Reference in New Issue
Block a user