ParserBase

ParserBase

A base class for parsers that handle text parsing with various options.

Constructor

new ParserBase(script, options)

Source:
Parameters:
Name Type Description
script string | Object

The input script to be parsed.

options Object

Additional options for the parser.

Properties
Name Type Description
onParseStart function

Callback function called when parsing starts.

onParseEnd function

Callback function called when parsing ends.

readEncoding string

Force this encoding when reading.

writeEncoding string

Force into this encoding when writing.

defaultEncoding string

Default encoding if not specified (default is "utf8").

translationPair Object

Translation pair for the parser.

translationInfo Object

Additional translation information.

contextSeparator string

Separator for context (default is "/").

baseParameter string | undefined

Base parameter for the parser.

baseContext Array

Base context for the parser.

baseTags Array

Base tags for the parser.

debugLevel number

Debugging level for the parser (default is 0).

Methods

assignTranslationPair(path, translationDatas) → {ParserBase}

Description:
  • Set translation pair from translationDatas
    If translationDatas is not set, this.options.translationDatas is used

Source:
Parameters:
Name Type Description
path

local path

translationDatas

Collection of translation data

Returns:
Type
ParserBase

contextEnd()

Description:
  • End the current context.

Source:

contextEnter(…arguments)

Description:
  • Enter one or more contexts.

Source:
Parameters:
Name Type Attributes Description
arguments string <repeatable>

Contexts to enter.

editLastWritableData(string) → {string}

Description:
  • Edit the last string in the writable data array.

Source:
Parameters:
Name Type Description
string string

The new string to replace the last one.

Returns:
  • The edited string.
Type
string

filterText(text, context, parameters)

Description:
  • Filter text for Translator++ front end
    Please overwrite this function based on the engine

Source:
Parameters:
Name Type Description
text
context
parameters

generateFileInfo(relativePath) → {Object}

Description:
  • Generate file information for the current instance from the given relative path.

Source:
Parameters:
Name Type Description
relativePath string

The relative path of the file.

Returns:
  • An object containing file information.
Type
Object

getText() → {string}

Description:
  • Get the parsed text.

Source:
Returns:
  • The parsed text.
Type
string

importTransData(exportedObj)

Description:
  • Import transData from another parsed instance of ParserBase.

Source:
Parameters:
Name Type Description
exportedObj Object

The exported object containing transData.

processThispath(relPath) → {Boolean}

Description:
  • Determine whether the file path should be processed or not
    True : process
    False : should not process

Source:
Parameters:
Name Type Description
relPath String

Path's key

Returns:
Type
Boolean

register(string) → {string}

Description:
  • Register a string to the writable data array.

Source:
Parameters:
Name Type Description
string string

The string to register.

Returns:
  • The registered string.
Type
string

registerString(string, localContextopt, parametersopt, optionsopt) → {String}

Description:
  • Register a translatable string

Source:
Parameters:
Name Type Attributes Description
string String

Translatable string to register

localContext Array.<String> | undefined <optional>

Local context. The overall context will be appended into ParserBase.baseContext

parameters Object | undefined <optional>

Parameters to be added

options Object | undefined <optional>

Options to pass misc data

Properties
Name Type Attributes Description
defaultObject Object | undefined <optional>

default object to be stored to the translatableTexts

currentAddress Object | undefined <optional>

Current address

defaultTranslation String | undefined <optional>

Register default translation

Returns:
  • Translated string if match translation, Original string if no translation is found.
Type
String

replaceLineBreak(text) → {string}

Description:
  • Replace line breaks in the given text.

Source:
Parameters:
Name Type Description
text string

The text to process.

Returns:
  • The text with line breaks replaced.
Type
string

setTranslationPair(translationPair) → {ParserBase}

Description:
  • Apply translation pair

Source:
Parameters:
Name Type Description
translationPair Object

Translation Pair

Returns:
Type
ParserBase

toString() → {string}

Description:
  • Convert the ParserBase instance to a string.

Source:
Returns:
  • The concatenated writableData string.
Type
string

toTrans() → {Promise.<Object>}

Description:
  • Asynchronously get the transData after parsing if not already parsed.

Source:
Returns:
  • A promise resolving to the transData.
Type
Promise.<Object>

translate(text, context) → {String}

Description:
  • Translate text based on this.translationPair

Source:
Parameters:
Name Type Description
text String

Text to be translated

context Array

Array of the current context

Returns:
  • Translation
Type
String

unfilterText(text, context, parameters)

Description:
  • Unfilter text to prepare the data to be exported
    Please overwrite this function based on the engine

Source:
Parameters:
Name Type Description
text
context
parameters

(static) appendTransData(originalTrans, newTrans) → {Object}

Description:
  • Append transData from a new parsed instance to the original transData.

Source:
Parameters:
Name Type Description
originalTrans Object

The original transData.

newTrans Object

The new transData to append.

Returns:
  • The combined transData.
Type
Object

(static) detectEncoding(buffer) → {string}

Description:
  • Detect the encoding of the given buffer.

Source:
Parameters:
Name Type Description
buffer Buffer

The buffer to detect encoding from.

Returns:
  • The detected encoding.
Type
string

(static) generateFileInfo(relativePath) → {Object}

Description:
  • Generate file information from the given relative path.

Source:
Parameters:
Name Type Description
relativePath string

The relative path of the file.

Returns:
  • An object containing file information.
Type
Object