Constructor
new CustomParser(script, options, callback)
- Description:
Creates an instance of CustomParser.
- Source:
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
script |
string | The script to parse. |
|||||||||
options |
object | Options for parsing. Properties
|
|||||||||
callback |
function | Callback function. |
Extends
Members
model :object
- Description:
The model data.
- Source:
The model data.
Type:
- object
transData :object
- Description:
The transData object.
- Source:
Properties:
Name | Type | Description |
---|---|---|
data |
Array | The data array. |
context |
Array | The context array. |
tags |
Array | The tags array. |
parameters |
Array | The parameters array. |
indexIds |
object | The indexIds object. |
The transData object.
Type:
- object
Methods
assignTranslationPair(path, translationDatas) → {ParserBase}
- Description:
Set translation pair from translationDatas
If translationDatas is not set, this.options.translationDatas is used
- Source:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
path |
local path |
|
translationDatas |
Collection of translation data |
Returns:
- Type
- ParserBase
contextEnd()
- Description:
End the current context.
- Source:
- Overrides:
contextEnter(…arguments)
- Description:
Enter one or more contexts.
- Source:
- Overrides:
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:
- Overrides:
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:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
text |
||
context |
||
parameters |
generateFileInfo(relativePath) → {Object}
- Description:
Generate file information for the current instance from the given relative path.
- Source:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
relativePath |
string | The relative path of the file. |
Returns:
- An object containing file information.
- Type
- Object
getModel() → {object}
- Description:
Gets the model.
- Source:
Returns:
The model.
- Type
- object
getText() → {string}
- Description:
Get the parsed text.
- Source:
- Overrides:
Returns:
- The parsed text.
- Type
- string
importTransData(exportedObj)
- Description:
Import transData from another parsed instance of ParserBase.
- Source:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
exportedObj |
Object | The exported object containing transData. |
off(evt, fn)
- Description:
Event unsubscription method.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
evt |
string | Event name. |
fn |
function | Event handler function. |
on(evt, fn)
- Description:
Event subscription method.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
evt |
string | Event name. |
fn |
function | Event handler function. |
one(evt, fn)
- Description:
Event subscription method for a single occurrence.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
evt |
string | Event name. |
fn |
function | Event handler function. |
parse()
- Description:
Parses the script.
- Source:
parseCaptureGroup(str) → {Array}
- Description:
Parses a capture group.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
string | Array | The string or array to parse. |
Returns:
The parsed capture group.
- Type
- Array
processThispath(relPath) → {Boolean}
- Description:
Determine whether the file path should be processed or not
True : process
False : should not process
- Source:
- Overrides:
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:
- Overrides:
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:
- Overrides:
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
|
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:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
text |
string | The text to process. |
Returns:
- The text with line breaks replaced.
- Type
- string
setModel(model) → {object}
- Description:
Sets the model.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
model |
object | Model object. |
Returns:
The set model.
- Type
- object
setTranslationPair(translationPair) → {ParserBase}
- Description:
Apply translation pair
- Source:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
translationPair |
Object | Translation Pair |
Returns:
- Type
- ParserBase
toString() → {string}
- Description:
Converts CustomParser instance to string.
- Source:
- Overrides:
Returns:
The string representation of the instance.
- Type
- string
toTrans() → {Promise.<Object>}
- Description:
Asynchronously get the transData after parsing if not already parsed.
- Source:
- Overrides:
Returns:
- A promise resolving to the transData.
- Type
- Promise.<Object>
translate(text, context) → {String}
- Description:
Translate text based on this.translationPair
- Source:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
text |
String | Text to be translated |
context |
Array | Array of the current context |
Returns:
- Translation
- Type
- String
trigger(evt, param)
- Description:
Triggers an event.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
evt |
string | Event name. |
param |
* | Event parameter. |
unfilterText(text, context, parameters)
- Description:
Unfilter text to prepare the data to be exported
Please overwrite this function based on the engine
- Source:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
text |
||
context |
||
parameters |
(static) isValidModel(model) → {boolean}
- Description:
Checks if the provided model is valid.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
model |
object | string | The model object or JSON string. |
Returns:
True if the model is valid, otherwise false.
- Type
- boolean