translate

translate

PREMIUM TRIAL / ADVANCED

Translates contents in a DOCX document.

Description
public translate ( $source [, array $options = array()] )

Translates contents in a DOCX, replaces contents.

Supported AI integrations:

  • GPT OpenAI
Parameters

source

DOCX document.

options

An array with the available options.

The possible keys and values are:

key Type Description
frequency_penalty float Default as 0.0.
max_tokens int Default as 1000. Each OpenAI model limits max tokens.
model string Default as 'text-davinci-003'.
presence_penalty float Default as 0.0.
prompt string Default as 'Translate this into English:'.
referenceNode array Default all paragraphs. DOCXPath options for custom queries:
  • 'type' (string) paragraph (default)
  • 'contains' (string)
  • 'occurrence' (int)
  • 'attributes' (array)
  • 'parent' (string) '/' (any parent, default), w:body or any other specific parent (/w:tbl/, /w:tc/, /w:r/...)
  • 'customQuery' (string) if set overwrites all previous references. It must be a valid XPath query
returnFullResponse bool If true returns the whole GPT response. Default as false.
saveAs string If set, generates a new DOCX replacing the contents by the translations. Paragraph styles are kept but run-of-text styles are removed. Existing internal references in the paragraph are added to the beginning of each paragraph. Default as null.
target array Extract specific targets:
  • document
  • headers
  • footers
  • footnotes
  • endnotes
  • comments
temperature float Default as 0.3.
top_p float Default as 1.0.
url string Default as 'https://api.openai.com/v1/completions'.
Return values

array with the contents

Exceptions

Not valid DOCX source.

Error connecting to GPT.

GPT error.

Code samples

Example #1

The resulting output looks like:

Example #2

The resulting output looks like: