@shawnvogt/strapi-plugin-google-translate
Version:
Strapi plugin for automated translation of content using Google Cloud Translation
59 lines (57 loc) • 2.05 kB
JavaScript
module.exports = {
default: ({ env }) => {
return {
apiKey: env('GOOGLE_TRANSLATE_KEY', null),
translatedFieldTypes: [
'string',
'text',
'richtext',
'component',
'dynamiczone',
],
translateRelations: true,
glossaryId: null,
// filterFieldNames is a list of strings: fields with names matching these strings will not be translated
filterFieldNames: [],
preserveUpstreamRelations: [],
// translateExclusion must be a function that receives arguments (data, schema)
// and must return either the original unmodified data object or a new data object with fields removed that should not be translated
// useful for when some of a content type should be translated and others not translated,
// caution: if fields are removed from the original data object the field will be empty
translateExclusions: null,
}
},
validator({
apiKey,
translatedFieldTypes,
translateRelations,
filterFieldNames,
preserveUpstreamRelations,
translateExclusions,
}) {
if (!apiKey) {
throw new Error(
'apiKey is not set, disable the plugin if you do not have one since the translations will not succeed'
)
}
if (typeof apiKey != 'string') {
throw new Error('apiKey must be a string')
}
if (!Array.isArray(translatedFieldTypes)) {
throw new Error('translatedFieldTypes has to bee an array')
}
if (typeof translateRelations !== 'boolean') {
throw new Error('freeApi has to be a boolean')
}
if (!Array.isArray(filterFieldNames)) {
throw new Error('filterFieldNames has to bee an array')
}
if (!Array.isArray(preserveUpstreamRelations)) {
throw new Error('preserveUpstreamRelations has to bee an array')
}
if (translateExclusions && typeof translateExclusions !== 'function') {
throw new Error('translateExclustions must be a function')
}
},
}