Loading...
Searching...
No Matches
TranslationPlugin Interface Reference

This plugin contacts an API through JSON to obtain translations from selected rows. More...

Inheritance diagram for TranslationPlugin:
LocalizationEditorPlugin WorkbenchPlugin Managed

Public Member Functions

override void OnStringTableItemContextMenu ()
 
- Public Member Functions inherited from LocalizationEditorPlugin
void OnSave (BaseContainer stringTable, string stringTableItemClassName, string stringTableAbsPath)
 
void OnChange (BaseContainer stringTableItem, string propName, string propValue)
 
void OnImport (BaseContainer newItem, BaseContainer oldItem)
 
void OnExport (BaseContainer item)
 
void OnSelectionChanged ()
 
bool IsReadOnly (BaseContainer item, bool isImporting)
 
string GetExportColumn (BaseContainer item, string languageCode)
 Called for each item during building runtime table, expected column name to export for given language.
 
- Public Member Functions inherited from WorkbenchPlugin
void RunCommandline ()
 
void OnResourceContextMenu (notnull array< ResourceName > resources)
 
- Public Member Functions inherited from Managed
proto external ref Managed Clone ()
 Return shallow copy of object, or null if it is not allowed (not public constructor)
 

Static Public Member Functions

static string SanitizeToken (string token)
 Sanitise the provided token to prevent a potential headers exploit.
 

Protected Member Functions

override void Run ()
 
bool CheckFields (notnull BaseContainer item)
 Check if Id, Default Source and eventually Default Source Edited config fields are correct.
 
bool StartProcess (notnull map< string, ref TranslationPlugin_DataWrapper > idWrapperMap)
 Send REST request or Simulate.
 
bool SendRequest (notnull RestApi restAPI, notnull TranslationPluginRequest request)
 
void REST_OnSuccess (RestCallback cb=null)
 Method called by m_RestCallback's OnSuccess calls ProcessSuccessResponse quickly, kept short for simulation purpose.
 
void ProcessSuccessResponse (notnull TranslationPluginResponse response)
 Processes successful response, whether real or simulated.
 
void REST_OnError (RestCallback cb=null)
 Method called by m_RestCallback's OnError - calls ProcessErrorResponse quickly, kept short for simulation purpose.
 
void ProcessErrorResponse (HttpCode errorCode, ERestResult restResult)
 Processes error response, whether real or simulated.
 
map< string, ref TranslationPlugin_DataWrapperGetIdWrapperMap (notnull BaseContainerList stringTableItems, notnull array< int > rowsToTranslate)
 Get required translations from selected/filtered rows.
 
TranslationPlugin_DataWrapper CreateDataWrapper (string id, notnull BaseContainer item)
 
map< string, stringGetAllItemTranslations (notnull BaseContainer item)
 
int ApplyTranslations (notnull LocalizationEditor stringEditor, notnull TranslationPluginResponse response)
 Apply translations to the stringtable.
 
void ResetRequestState ()
 Reset variables to brand new.
 
TranslationPluginResponse GetFakeResponse ()
 Get a fake response based on requested ids and locales.
 
void ResetConfig ()
 Set a config with the attributes's default values.
 
bool LoadConfig (ResourceName resourceName)
 
override void Configure ()
 
bool ConfigureClose ()
 
bool ConfigureValidate ()
 
bool ConfigureLoadConfig ()
 
int ButtonLoadConfig ()
 
int ButtonValidateClose ()
 
int ButtonClose ()
 

Static Protected Member Functions

static string GetTranslationFromLocale (string locale, notnull TranslationPluginResultHolder holder)
 Get the holder's translation corresponding to the locale.
 
static bool SplitURL (string url, out string protocol, out string address, out string query)
 
static bool AreLocalesEqual (notnull array< string > localesA, notnull array< string > localesB)
 
static void PrintDialog (string message, string caption, LogLevel level)
 Print and show a Workbench dialog.
 
static void PrintFormatDialog (string message, string param1, string param2="", string param3="", string caption="", LogLevel level=LogLevel.WARNING)
 Print and show a Workbench dialog.
 
static string FormatDurationMs (int milliSeconds)
 Format provided milliseconds into user-friendly time.
 

Protected Attributes

bool m_bDisableLocalesGrouping
 
ETranslationPlugin_EditedRowsMode m_eEditedEntriesMode
 
bool m_bOverwriteExistingTranslations
 
bool m_bSetEditedAsOriginal
 
string m_sServerURL
 
string m_sServerToken
 
bool m_bDisplayAdvancedStatsOnSuccess
 
ref TranslationPluginMatchConfig m_MatchConfig
 
bool m_bLogChanges
 
bool m_bLogNetwork
 
ETranslationPlugin_ProcessMode m_eProcessMode
 
ref map< string, ref TranslationPlugin_DataWrapperm_mIdDataMap
 
int m_iTranslationQueriesCount
 
ref array< stringm_aGlobalLocales
 
bool m_bWaitingOnRestAPI
 
int m_iLastUsage
 
ref RestCallback m_RestCallback
 
ref WBProgressDialog m_ProgressBar
 

Static Protected Attributes

static const string PLUGIN_NAME = "Translation plugin"
 
static const string SOURCE_ID = "SOURCE"
 
static const string SOURCE_EDITED_ID = "SOURCE_EDITED"
 
static const int MAX_DISPLAYED_IDS = 6
 max item ids displayed in the "are you sure?" modal
 
static const int GENDER_MALE_INDEX = 1
 
static const int GENDER_FEMALE_INDEX = 2
 
static const int GENDER_OTHER_INDEX = 3
 
static const string GENDER_MALE_VALUE = "M"
 
static const string GENDER_FEMALE_VALUE = "F"
 
static const string GENDER_OTHER_VALUE = "O"
 
static const string PROTOCOL_SEPARATOR = ":/" + "/"
 
static const string DEFAULT_PROTOCOL = "https"
 
static const ref array< stringACCEPTED_PROTOCOLS = { "http" + PROTOCOL_SEPARATOR, DEFAULT_PROTOCOL + PROTOCOL_SEPARATOR }
 
static const string TOKEN_WHITELIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~+/="
 

Detailed Description

This plugin contacts an API through JSON to obtain translations from selected rows.


  • Locales are determined by removing the provided prefix from its attributes (e.g Target_en_us - Target_ = en_us)
  • Locale matchings and meta fields are defined in the Match Config (see this config as a "stringtable item codec")

Member Function Documentation

◆ ApplyTranslations()

int TranslationPlugin.ApplyTranslations ( notnull LocalizationEditor stringEditor,
notnull TranslationPluginResponse response )
protected

Apply translations to the stringtable.

Parameters
[in]stringEditorrequired to set the edits
[in]responsethe server's response
Returns
number of changed rows

◆ AreLocalesEqual()

static bool TranslationPlugin.AreLocalesEqual ( notnull array< string > localesA,
notnull array< string > localesB )
staticprotected
Parameters
[in]localesA
[in]localesB
Returns
true if arrays are identical, false otherwise (casing and order matter)

◆ ButtonClose()

int TranslationPlugin.ButtonClose ( )
protected

◆ ButtonLoadConfig()

int TranslationPlugin.ButtonLoadConfig ( )
protected

◆ ButtonValidateClose()

int TranslationPlugin.ButtonValidateClose ( )
protected

◆ CheckFields()

bool TranslationPlugin.CheckFields ( notnull BaseContainer item)
protected

Check if Id, Default Source and eventually Default Source Edited config fields are correct.

Parameters
[in]item
Returns
true on success, false otherwise

◆ Configure()

override void TranslationPlugin.Configure ( )
protected

Implements WorkbenchPlugin.

◆ ConfigureClose()

bool TranslationPlugin.ConfigureClose ( )
protected
Returns
always true

◆ ConfigureLoadConfig()

bool TranslationPlugin.ConfigureLoadConfig ( )
protected
Returns
always true

◆ ConfigureValidate()

bool TranslationPlugin.ConfigureValidate ( )
protected
Returns
true if everything went well, false otherwise (and need to reopen Configure())

◆ CreateDataWrapper()

TranslationPlugin_DataWrapper TranslationPlugin.CreateDataWrapper ( string id,
notnull BaseContainer item )
protected
Parameters
[in]id
[in]item
Returns
a wrapper instance if a translation is needed, null otherwise

◆ FormatDurationMs()

static string TranslationPlugin.FormatDurationMs ( int milliSeconds)
staticprotected

Format provided milliseconds into user-friendly time.

Parameters
[in]milliSecondsthe absolute value is taken
Returns
a string in format "00:00:00", "00:00", "x0.0s" or "no time" depending on time (respectively >= 60 min, >= 60s, anything else but 0, 0)

◆ GetAllItemTranslations()

map< string, string > TranslationPlugin.GetAllItemTranslations ( notnull BaseContainer item)
protected
Parameters
[in]item
Returns
locale-translation map + SOURCE_ID-translation / SOURCE_EDITED_ID-translation, never null

◆ GetFakeResponse()

TranslationPluginResponse TranslationPlugin.GetFakeResponse ( )
protected

Get a fake response based on requested ids and locales.

Returns
a response that could come from JSON

◆ GetIdWrapperMap()

map< string, ref TranslationPlugin_DataWrapper > TranslationPlugin.GetIdWrapperMap ( notnull BaseContainerList stringTableItems,
notnull array< int > rowsToTranslate )
protected

Get required translations from selected/filtered rows.

Parameters
[in]stringTableItems
[in]rowsToTranslate
Returns
a map filled with id-dataWrapper key-value pairs, or empty - never null

◆ GetTranslationFromLocale()

static string TranslationPlugin.GetTranslationFromLocale ( string locale,
notnull TranslationPluginResultHolder holder )
staticprotected

Get the holder's translation corresponding to the locale.

Parameters
[in]localee.g fr_fr
[in]holderthe translation holder to parse
Returns
the translation, empty string if locale is not found or on error

◆ LoadConfig()

bool TranslationPlugin.LoadConfig ( ResourceName resourceName)
protected
Parameters
[in]resourceNamethe config to load
Returns
true on success, false otherwise

◆ OnStringTableItemContextMenu()

override void TranslationPlugin.OnStringTableItemContextMenu ( )

◆ PrintDialog()

static void TranslationPlugin.PrintDialog ( string message,
string caption,
LogLevel level )
staticprotected

Print and show a Workbench dialog.

Parameters
[in]message
[in]caption
[in]level

◆ PrintFormatDialog()

static void TranslationPlugin.PrintFormatDialog ( string message,
string param1,
string param2 = "",
string param3 = "",
string caption = "",
LogLevel level = LogLevel::WARNING )
staticprotected

Print and show a Workbench dialog.

Parameters
[in]message
[in]param1
[in]param2
[in]param3
[in]caption
[in]level

◆ ProcessErrorResponse()

void TranslationPlugin.ProcessErrorResponse ( HttpCode errorCode,
ERestResult restResult )
protected

Processes error response, whether real or simulated.

Parameters
[in]errorCode
[in]restResult

◆ ProcessSuccessResponse()

void TranslationPlugin.ProcessSuccessResponse ( notnull TranslationPluginResponse response)
protected

Processes successful response, whether real or simulated.

Parameters
[in]response

◆ ResetConfig()

void TranslationPlugin.ResetConfig ( )
protected

Set a config with the attributes's default values.

◆ ResetRequestState()

void TranslationPlugin.ResetRequestState ( )
protected

Reset variables to brand new.

◆ REST_OnError()

void TranslationPlugin.REST_OnError ( RestCallback cb = null)
protected

Method called by m_RestCallback's OnError - calls ProcessErrorResponse quickly, kept short for simulation purpose.

Parameters
[in]cb

◆ REST_OnSuccess()

void TranslationPlugin.REST_OnSuccess ( RestCallback cb = null)
protected

Method called by m_RestCallback's OnSuccess calls ProcessSuccessResponse quickly, kept short for simulation purpose.

Parameters
[in]cb

◆ Run()

override void TranslationPlugin.Run ( )
protected

Implements WorkbenchPlugin.

◆ SanitizeToken()

static string TranslationPlugin.SanitizeToken ( string token)
static

Sanitise the provided token to prevent a potential headers exploit.

Parameters
[in]tokenthe token to sanitise
Returns
the sanitised token format ^[a-zA-Z0-9-._~+/=]$, or empty string on bad/empty token

◆ SendRequest()

bool TranslationPlugin.SendRequest ( notnull RestApi restAPI,
notnull TranslationPluginRequest request )
protected

◆ SplitURL()

static bool TranslationPlugin.SplitURL ( string url,
out string protocol,
out string address,
out string query )
staticprotected
Parameters
[in]urlin format http(s)://anything(/)(?xyz), e.g:
[out]protocolhttp:// or https://
See also
ACCEPTED_PROTOCOLS
Parameters
[out]addressthe API's address e.g https://localhost/path/to/api, NOT server root address
[out]querywhat comes after the question mark in the URL (e.g mode=translate&version=1.5, without question mark)
Returns
true on successfully splitting address and query (even if query is empty), false otherwise

◆ StartProcess()

bool TranslationPlugin.StartProcess ( notnull map< string, ref TranslationPlugin_DataWrapper > idWrapperMap)
protected

Send REST request or Simulate.

Parameters
[in]idWrapperMapmap with required translations
Returns
true on success, false otherwise

Member Data Documentation

◆ ACCEPTED_PROTOCOLS

const ref array<string> TranslationPlugin.ACCEPTED_PROTOCOLS = { "http" + PROTOCOL_SEPARATOR, DEFAULT_PROTOCOL + PROTOCOL_SEPARATOR }
staticprotected

◆ DEFAULT_PROTOCOL

const string TranslationPlugin.DEFAULT_PROTOCOL = "https"
staticprotected

◆ GENDER_FEMALE_INDEX

const int TranslationPlugin.GENDER_FEMALE_INDEX = 2
staticprotected

◆ GENDER_FEMALE_VALUE

const string TranslationPlugin.GENDER_FEMALE_VALUE = "F"
staticprotected

◆ GENDER_MALE_INDEX

const int TranslationPlugin.GENDER_MALE_INDEX = 1
staticprotected

◆ GENDER_MALE_VALUE

const string TranslationPlugin.GENDER_MALE_VALUE = "M"
staticprotected

◆ GENDER_OTHER_INDEX

const int TranslationPlugin.GENDER_OTHER_INDEX = 3
staticprotected

◆ GENDER_OTHER_VALUE

const string TranslationPlugin.GENDER_OTHER_VALUE = "O"
staticprotected

◆ m_aGlobalLocales

ref array<string> TranslationPlugin.m_aGlobalLocales
protected

◆ m_bDisableLocalesGrouping

bool TranslationPlugin.m_bDisableLocalesGrouping
protected

◆ m_bDisplayAdvancedStatsOnSuccess

bool TranslationPlugin.m_bDisplayAdvancedStatsOnSuccess
protected

◆ m_bLogChanges

bool TranslationPlugin.m_bLogChanges
protected

◆ m_bLogNetwork

bool TranslationPlugin.m_bLogNetwork
protected

◆ m_bOverwriteExistingTranslations

bool TranslationPlugin.m_bOverwriteExistingTranslations
protected

◆ m_bSetEditedAsOriginal

bool TranslationPlugin.m_bSetEditedAsOriginal
protected

◆ m_bWaitingOnRestAPI

bool TranslationPlugin.m_bWaitingOnRestAPI
protected

◆ m_eEditedEntriesMode

ETranslationPlugin_EditedRowsMode TranslationPlugin.m_eEditedEntriesMode
protected

◆ m_eProcessMode

ETranslationPlugin_ProcessMode TranslationPlugin.m_eProcessMode
protected

◆ m_iLastUsage

int TranslationPlugin.m_iLastUsage
protected

◆ m_iTranslationQueriesCount

int TranslationPlugin.m_iTranslationQueriesCount
protected

◆ m_MatchConfig

ref TranslationPluginMatchConfig TranslationPlugin.m_MatchConfig
protected

◆ m_mIdDataMap

ref map<string, ref TranslationPlugin_DataWrapper> TranslationPlugin.m_mIdDataMap
protected

◆ m_ProgressBar

ref WBProgressDialog TranslationPlugin.m_ProgressBar
protected

◆ m_RestCallback

ref RestCallback TranslationPlugin.m_RestCallback
protected

◆ m_sServerToken

string TranslationPlugin.m_sServerToken
protected

◆ m_sServerURL

string TranslationPlugin.m_sServerURL
protected

◆ MAX_DISPLAYED_IDS

const int TranslationPlugin.MAX_DISPLAYED_IDS = 6
staticprotected

max item ids displayed in the "are you sure?" modal

◆ PLUGIN_NAME

const string TranslationPlugin.PLUGIN_NAME = "Translation plugin"
staticprotected

◆ PROTOCOL_SEPARATOR

const string TranslationPlugin.PROTOCOL_SEPARATOR = ":/" + "/"
staticprotected

◆ SOURCE_EDITED_ID

const string TranslationPlugin.SOURCE_EDITED_ID = "SOURCE_EDITED"
staticprotected

◆ SOURCE_ID

const string TranslationPlugin.SOURCE_ID = "SOURCE"
staticprotected

◆ TOKEN_WHITELIST

const string TranslationPlugin.TOKEN_WHITELIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~+/="
staticprotected

The documentation for this interface was generated from the following file: