Custom Pattern

⌘K
  1. Home
  2. Translator++
  3. Code Escaping Algorithm
  4. Custom Pattern

Custom Pattern

Code escaper is a feature that will let us exclude some words, phrases, codes when performing batch translations.

This feature is useful for escaping codes, path to resources or any string that should not be translated from being translated by machine when doing batch translation.

How to access the tool

Options window → Translator & Language → Custom Escaper → Patterns

How to write the patterns

Patterns are valid JavaScript strings, functions, or Regular Expressions. Each pattern is separated by a comma.

Literal Strings

We can write patterns with literal javascript strings. This is useful to escape simple phrases or a word.

  • String is a JavaScript strings
  • Strings are enclosed with double quotes, single quotes or a backticks (template literals).
  • You must escape special characters with a backslash (for example type backslash with double backslash)

Example

"literal string",
"\\E"

Functions

We can write patterns with a javascript function. You can access all javascript’s native function and Translator++ environment’s function.

This functionality is useful for escaping miscellaneous words, for example to exclude the first line of each message, etc.

  • Function is unnamed function
  • Any type of functions are acceptable (async function, arrow functions)
  • First parameters are the current string of the text, that can be the entire text key of each row (on row-by-row mode) or each line of each row (on line-by-line mode)
  • The function should returns array of string to be escaped

Example

function(currentText) { 
	return ["string to escape", "string to escape 2"] 
}

Regular expressions

Regular expressions also can be used to filter out text from translation.

  • Any form of Ecmascript regular expressions are accepted
  • Write regular expressions along with its modifier

Example

/(if|en)\([\w \=\[\]\&<\>\|\.\$\_\+\-\*\/\@\!]+\)/g,
/(\\[a-zA-Z0-9]+\[.*?\])+/gi,
/(\\[a-zA-Z0-9]+<.*?\>)+/gi,
/(\\[a-zA-Z\{\}\\\$\.\|\!\><\^])+/g,
/(\@[0-9]+)+/g,
/\%[1-9]+/g,

Commenting

Pattern fields also allow us to put JavaScript styled comments such as double slash for line commenting, or multiple line commenting with /* */

/* Conditional choice plugin */
/(if|en)\([\w \=\[\]\&<\>\|\.\$\_\+\-\*\/\@\!]+\)/g,
/* RPG maker tags */
/(\\[a-zA-Z0-9]+\[.*?\])+/gi,
/(\\[a-zA-Z0-9]+<.*?\>)+/gi,
/(\\[a-zA-Z\{\}\\\$\.\|\!\><\^])+/g,

Creating pattern with ChatGPT

With the advance of AI, you can generate regular expression or javascript function with ChatGPT.

Sample prompt

Create a JavaScript regular expression to capture a subset of string.
For example.
Input string:
Lorem \N[John] ipsum \{dolor\} sit amet. \i[12]

Captured strings:
\N[John]
\{
\}
\i[12]

Result

Was this article helpful to you? No 14 Yes 2

How can we help?