1. Home
  2. Docs
  3. Translator++
  4. Execute Script
  5. Custom Script

Custom Script

Information

This page is in the process of being written. Please come back again another time.

Workspaces

Custom scripts in Translator++ are divided into 5 different workspaces: global workspace, object level, row level, cell level, and found cells (in search window)

There is no built in iterator in the global workspace.

1. Global workspace

There is no built in iterator on Global level workspace

Global workspace

2. Object based iterator

In this workspace the script will be executed for each selected object (or all if none selected)

Object level iterator

3. Row based iterator

In this workspace the script will be executed for each row within selected object (or all if none selected).

Row level iterator

4. Cell based iterator

In this workspace the script will be executed for each cell (row and column) within selected object (or all if none selected).

Cell based iterator available on the context menu of the grid

5. Found cells

Cell based iterator also available through search menu

Global properties and function

Variables

Warning

All variable (and constant) declared using var, const and let inside custom script will not available on the next iteration.

Use global scoped variable (such as: window) to make the variables available across iteration.

For example, take a look at the following example:

JS
The comparison between local scoped variable and global scoped variable

Functions

In addition to the Translator++ standard library, you can also use the following functions that were created specifically for the iteration framework.

die(lastMessage:string)

Immediately halt the iteration process


Object level iterator

“this” keyword

On object level, you can access the properties of the current object via this keyword.

this.file

String: the ID of the current object

this.index

Integer: the current index of iteration

Example

JS

this.maxIndex

Integer: Maximum index of current execution

this.isLast

Boolean: True if the current iteration is the last from the process.


Row level iterator

Execute javascript code for each row of the selected (checked) object in the project.

If no objects are selected then all object will be processed.

“this” keyword

All information of the current data are stored in the this keyword.

Row level iterator can use all the this properties from the Object level iterator. In addition, the cell based iterator has the following properties:

this.file

String: Id of the current object

Example

JS
JS
JS

this.rowId

Integer: The index of the row

this.keyText

String: The key text

Example

JS

this.cells

Array: the cells in the current row

Example

JS
JS

this.tags

Array: the tags of the current row

Example

JS

this.parameters

Object: the parameters of the current row

this.context

Array: the context of the current row

JS

this.comments

Array: the comments of the current row. Index of the comments represents its cell id.

Example

Example 1

Remove the new line from all messages. Keep the newline if the first or the last line are not Japanese.

JS

Example 2

Replaces the first line of translated text with the first line of original text

JS

Cell level iterator

“this” keyword

Cell level iterator can use all the this properties from the Object level iterator and Row level iterator. In addition, the cell level iterator has the following properties:

this.colId

Integer: The index of the cell

this.text

String: The text of the cell

This is a read only property

this.cellCoords

Obj: Coordinate of the cell

JS

Methods

this.setText(string)

Set text into the current cell

Example

Translate found cells with Sugoi Trans (excludes the first or the last row in the message)

JS
Tags , , ,
Was this article helpful to you? Yes 1 No