{"version":3,"file":"translation-helper.mjs","sources":["../../../lib/data-provider-interface/utils/translation-helper.js"],"sourcesContent":["import { has, isObject } from 'lodash-es';\nimport { useI18n } from 'vue-i18n';\n\n/**\n * Translation of each translatable parameter within the given structure if a translation is available\n * @param {*} propertyDefinition Object containing parameters defining the form and their content\n * @param {String} property String defining which property translation should be used\n */\n\nfunction translateProperty(propertyDefinition, property, t, te) {\n\n    if (has(propertyDefinition, 'identifier')) { // hidden fields don't need a label and have no identifier\n        const translatableParameters = ['label', 'info', 'help', 'placeholder', 'add-label'];\n        const propertyName = propertyDefinition.identifier;\n\n        for (let valueIndex = 0; valueIndex < translatableParameters.length; valueIndex += 1) {\n            let translation = propertyName;\n            const parameter = translatableParameters[valueIndex];\n\n            const translationExsists = te(`message.dataupload.${property}.${propertyName}.${parameter}`);\n            const translationExsistsEN = te(`message.dataupload.${property}.${propertyName}.${parameter}`, 'en');\n\n            // Check if translation exists\n            if (!has(property, parameter)) {\n                if (translationExsists) {\n                    translation = t(`message.dataupload.${property}.${propertyName}.${parameter}`);\n                } else if (translationExsistsEN) {\n                    translation = t(`message.dataupload.${property}.${propertyName}.${parameter}`, 'en');\n                } else {\n                    translation = parameter;\n                }\n\n                const isCustomComponentWithProps = !!propertyDefinition.$cmp\n                    && !propertyDefinition.$formkit\n                    && isObject(propertyDefinition.props);\n\n                const isSelectControlledGroupCustomComponent = isCustomComponentWithProps\n                    && propertyDefinition.$cmp === 'SelectControlledGroup';\n\n                if (isSelectControlledGroupCustomComponent) {\n                    propertyDefinition.props[parameter] = translation;\n                } else {\n                    propertyDefinition[parameter] = translation;\n                }\n\n                // if (parameter === \"info\") {\n\n                //     propertyDefinition['sections-schema'] = { prefix: { $el: 'div', attrs: { class: 'infoI', }, children: [{ $el: 'div', children: translation, attrs: { class: 'tooltipFormkit' } }] } }\n                // }\n            }\n\n            // Highlight mandatory fields\n            if (propertyDefinition.mandatory && parameter === \"label\") propertyDefinition[parameter] = `${translation}*`\n        }\n    }\n}\n\n/**\n * Recursive translation of propertie parameters including recursive translation of nested properties\n * @param {Object} schema Object containing the forms schema\n * @param {String} property String defining which property translation should be used (datasets/ distribution/ catalogues)\n */\nfunction translate(schema, property, t, te) {\n    for (let index = 0; index < schema.length; index += 1) {\n        const schemaPropertyValues = schema[index];\n\n        // translation of group forms and their nested properties\n        if (has(schemaPropertyValues, 'children')) {\n            // group attributes should be translated too\n            translateProperty(schemaPropertyValues, property, t, te);\n            // translated nested properties\n            translate(schemaPropertyValues.children, property, t, te);\n            // translation of conditional forms and their nested properties\n        } else if (has(schemaPropertyValues, 'data')) {\n            // group attributes should be translated too\n            translateProperty(schemaPropertyValues, property, t, te);\n            // translate nested data\n            const dataKeys = Object.keys(schemaPropertyValues.data);\n            for (let keyIndex = 0; keyIndex < dataKeys.length; keyIndex += 1) {\n                const currentKey = dataKeys[keyIndex];\n                translate(schemaPropertyValues.data[currentKey], property, t, te);\n            }\n            // translation of 'normal' singular form properties\n        } else {\n            translateProperty(schemaPropertyValues, property, t, te);\n        }\n    }\n}\n\nexport default translate;\n"],"names":["translateProperty","propertyDefinition","property","t","te","has","translatableParameters","propertyName","valueIndex","translation","parameter","translationExsists","translationExsistsEN","isObject","translate","schema","index","schemaPropertyValues","dataKeys","keyIndex","currentKey"],"mappings":";;AASA,SAASA,EAAkBC,GAAoBC,GAAUC,GAAGC,GAAI;AAE5D,MAAIC,EAAIJ,GAAoB,YAAY,GAAG;AACvC,UAAMK,IAAyB,CAAC,SAAS,QAAQ,QAAQ,eAAe,WAAW,GAC7EC,IAAeN,EAAmB;AAExC,aAASO,IAAa,GAAGA,IAAaF,EAAuB,QAAQE,KAAc,GAAG;AAClF,UAAIC,IAAcF;AAClB,YAAMG,IAAYJ,EAAuBE,CAAU,GAE7CG,IAAqBP,EAAG,sBAAsBF,CAAQ,IAAIK,CAAY,IAAIG,CAAS,EAAE,GACrFE,IAAuBR,EAAG,sBAAsBF,CAAQ,IAAIK,CAAY,IAAIG,CAAS,IAAI,IAAI;AA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