Skip to content
Stand with Ukraine flag

Custom Translation in HTML Value Card

This recipe shows how to use custom translation keys inside an HTML Value Card widget. The i18n keys in the HTML template are automatically resolved to the user’s interface language.

  • A ThingsBoard PE instance with custom translation configured
  • A device sending temperature telemetry

Navigate to White labeling > Custom translation and add the following keys for the target language (e.g., German):

Term keyEnglishGermanDescription
custom.devices.smart-device.nameSmart DeviceIntelligentes GerätDevice name
custom.my-dashboard.titleMy DashboardMein DashboardDashboard title
custom.my-widget.telemetry-key.temperatureTemperatureTemperaturTelemetry key label
custom.my-widget.telemetry-value.low-temperatureLow temperatureNiedrigtemperaturLow temperature
custom.my-widget.telemetry-value.high-temperatureHigh temperatureHochtemperaturHigh temperature
custom.my-widget.telemetry-value.normal-temperatureNormal temperatureNormaltemperaturNormal temperature
  1. Open the dashboard in edit mode and click Add widget.

  2. Select HTML Value Card from the Cards widgets bundle.

  3. Specify the device and temperature telemetry key as the data source.

  4. Go to the Appearance tab and paste the following HTML into the HTML field:

<script>
var description = document.getElementsByClassName('description')[0];
var temperature = ${temperature};
if(temperature>=25){
description.innerText = "{i18n:custom.my-widget.telemetry-value.high-temperature}";
}else if(temperature<=19){
description.innerText = "{i18n:custom.my-widget.telemetry-value.low-temperature}";
}else{
description.innerText = "{i18n:custom.my-widget.telemetry-value.normal-temperature}"
}
</script>
<div class='card'>
<div class='content'>
<div class='column'>
<h1>{i18n:custom.devices.smart-device.name}</h1>
<div class='value'>
{i18n:custom.my-widget.telemetry-key.temperature}: ${temperature:0} °C
</div>
<div class='description'>
</div>
</div>
</div>
</div>
  1. Click Add, then save the dashboard.

The card displays dynamic text based on the temperature value and the user’s language: