2.13Framework.Translation object

The Framework.Translation object contains functions for translating text-variables into the user's selected language for the MyTrader platform. Note: the language cannot change while code is running. It requires the user to log out of the software, and log back in.

The Framework.Translation object contains two properties:

Property

Description

locale

An identifier for the selected language. May be a broad categorisation such as "en", or a sub-specification such as "zh-CN" or "zh-HK".

isRTL

True/false depending on whether the language is usually written right-to-left instead of left-to-right. Note: MyTrader automatically sets a CSS class on a widget's <body> depending on the text direction: either LTR or RTL. Widget CSS can therefore use BODY.RTL as a CSS selector for making changes to handle right-to-left languages.

The functions in Framework.Translation are as follows:

Function

Description

TranslateDOM()

Translates language variables in HTML

TranslateItem()

Translates a single language variable

$T()

Short-hand version of TranslateItem()

TranslateError()

Translates an error result into the equivalent text

TranslateTimeframe()

Translates a chart timeframe, such as 3600, into corresponding text

TranslateInstrumentCategory()

Translates a market category ID into corresponding text

For example, translating an individual text item:

var freeMarginText = Framework.TranslateItem("FreeMargin"); // = "Free margin"

Translating items in a block of HTML:

<table id="MetricsTable">

<tr>

<th title="{Balance}">{Balance}</th>

<th title="{Equity}">{Equity}</th>

<th title="{FloatingPL}">{FloatingPL}</th>

</tr>

</table>

// Translate all {variables} inside the MetricsTable element.

// Calling TranslateDOM() without a parameter scans the entire document body.

Framework.TranslateDOM(document.getElementById("MetricsTable"));