Automatically translate text content in specified fields using Google Translate API and create new fields with translated content
Parameter | Type | Description |
---|---|---|
sourceLanguage | string | The IETF language code of the source text (e.g., ‘en’ for English) |
targetLanguage | string | The IETF language code for the target language (e.g., ‘es’ for Spanish). This is also used to name the new field |
sheetSlug | string | The slug of the sheet that the plugin should listen to. Records from other sheets will be ignored |
fieldsToTranslate | string[] | An array of field keys (names) that should be translated. The plugin will only process these fields |
projectId | string | Your Google Cloud project ID associated with the Google Translate API |
keyFilename | string | The absolute or relative path to your Google Cloud service account key file (JSON) |
sheetSlug
. For each record, it will read the text from the fieldsToTranslate
, call the Google Translate API, and write the results to new fields. If a field to be translated is empty or null, it is skipped.
recordHook
with the provided Flatfile listener, which will automatically translate specified fields on records belonging to the configured sheet.
Signature:
listener
: FlatfileListener - An instance of a Flatfile listener to attach the hook toconfig
: TranslationConfig - The configuration object for the pluginvoid
- This function does not return a value. It modifies the listener instance directly.
FlatfileRecord
. It reads values from the fields specified in the config, translates them, and sets the translated values on new fields in the record.
Signature:
record
: FlatfileRecord - The record to processconfig
: TranslationConfig - A configuration object specifying languages, fields, and credentialsrecord
: FlatfileRecord - The record with new fields containing translated texterror?
: string - An error message if an issue occurred during processingrecord.addError()
, making it visible in the Flatfile UIfieldsToTranslate
, it is skipped without errorprojectId
and a path to a service account keyFilename
with appropriate permissions_{targetLanguage}
to the original field name (e.g., name
becomes name_es
). Ensure this does not conflict with existing fields in your sheet configuration.
string
fields. Behavior with other field types is undefinedconvertTranslatePlugin
is first called. Subsequent calls with different credentials will re-initialize the client