|
1
|
/** |
|
2
|
* Computes the count of translated fields based on the translatable fields configuration. |
|
3
|
* Only counts fields that are: |
|
4
|
* 1. In the translatableFields array for the entity type |
|
5
|
* 2. Have a non-null, non-empty value in the translations object |
|
6
|
* |
|
7
|
* @param translations - The translations JSON object from the translation record |
|
8
|
* @param translatableFields - Array of field names that are translatable for this entity type |
|
9
|
* @returns The count of translated fields |
|
10
|
*/ |
|
11
|
export function computeTranslatedFieldCount( |
|
12
|
translations: Record<string, unknown> | undefined | null, |
|
13
|
translatableFields: string[] | undefined | null |
|
14
|
): number { |
|
15
|
if (!translations || !translatableFields?.length) { |
|
16
|
return 0 |
|
17
|
} |
|
18
|
|
|
19
|
return translatableFields.filter((field) => { |
|
20
|
const value = translations[field] |
|
21
|
return value != null && value !== "" && value !== "null" |
|
22
|
}).length |
|
23
|
} |