Translating Metadata to a Different Language
Sisense enables you to translate metadata in your user's native language. Sisense metadata is displayed in your users' dashboards and includes the following:
- ElastiCube fields
- ElastiCube tables
- Widget Titles
- Dashboard Names
- Folder Names
- Saved formulas
- Default and custom hierarchies
- Customized renamed field titles
Note:
When the standard aggregation for a widget value is manually changed to a formula in the widget editor (even to other standard aggregations, such as Count to Dupcount), separate translations to be defined in the “formulas” section of the run.js code are required. This change can not be reverted, and the field will persist as custom formula in the widget until the field is deleted and added to the widget as a standard aggregation again.
The following images display two interfaces with metadata, one in English and the other in Russian.
English | Russian |
|
As fields such as ElastiCube names and tables are defined by you, these fields are not translated when changing the default language of the Sisense.
You can translate your metadata by modifying the default values using a JavaScript add-on. Through the add-on, you define the new values to be displayed. You may also include additional logic to determine which users or user groups the translated values should be displayed to.
When you create a JavaScript add-on, you should create a folder for the add-on and place it inside the plugins folder
in the following location:
/opt/sisense/storage/plugins/
OR
Upload all the folders to your Sisense Server through the File Manager. See Uploading Files to Customize Your Linux Deployment for more information.
If the /plugins/ folder does not exist, create it and then create a new folder within the /plugins/ folder with the relevant files.
You can download an example of a Metadata Translation plugin here. This is just an example, you define how your metadata is to be translated.
Extract the enclosed folder into the plugins folder.
This file contains a folder called Metadata and two files:
-
plugin.json - The plugin.json file contains the name of the add-on and a link to the file that describes the add-on's functionality, in this example, run.js.
-
run.js - The run.js file contains the add-on's functionality and describes which metadata is to be translated and how it is to be translated.
This example, and any metadata translation JavaScript file you write should include three parts:
- Provider Function: These functions provide the mapping context contained in the Mapping object.
- Event Subscription: This event is triggered when a datasource changes, and calls the Provider function.
- Mapping Object: Contains key/value pairs with your default and translated metadata.
Provider Functions
The code sample below is an example of two Provider functions, the first is a global provider function for folder and dashboard aliasing. The second is the datasource provider function for translating ElastiCube and formula names. You can replace the parameters in this example to provide the mapping context you define in the Mapping object.
Global Provider
function (resolve, reject) {
//an ajax request or any other logic.
setTimeout(function () {
resolve(globalAliasing);
}, 0);
};
The following table describes the Provider function and its arguments:
Parameter | Description |
---|---|
resolve | A callback function which should be called with the provided aliasing context object or without any parameter if aliases should not be provided for the datasource. |
reject | A callback function to be called in case of error, so the system can properly handle it. |
Datasource Provider
function (datasourceId, resolve, reject) {
//an ajax request or any other logic.
setTimeout(function () {
resolve(datasourceAliasing);
}, 0);
};
The following table describes the Provider function and its arguments:
Parameter | Description |
---|---|
datasourceId |
An object that represents the ID of the datasource with the following properties:
|
resolve | A callback function which should be called with the provided aliasing context object or without any parameter if aliases should not be provided for the datasource. |
reject | A callback function to be called in case of error, so the system can properly handle it. |
Grouping Provider
The config object allows you to segment translated content per group. For example, Group 1 can see dashboards
translated while group two can see the Data page translated. In the config object, you define the
groupId and what alias is assigned to that group.
var config = [
{
"groupId":"5bbb4d8fd8528537d5604777",
"aliasName":datasourceAliasing
},
{
"groupId":"5bf3c5035f56071a1cf1b37c",
"aliasName":datasourceAliasing_1
}
The following table describes the Provider function and its arguments:
Parameter | Description |
---|---|
groupID | Defines the group that an alias is to be assigned to.
You can retrieve the groupId through the GET /groups endpoint in the Sisense REST API. |
aliasname | Defines which alias object to use for the group defined in the groupID. |
Event Subscription
To trigger the Provider functions, your add-on should include a handler for a global event 'beforealiascontextinit'.
In the example below, datasourceProviderFunction and globalAliasingProvider are the Provider functions. The timeout parameter is optional and configures the amount of time in milliseconds which the system waits for the aliasing context to be resolved by the provider function. By default the system uses a timeout of 2000 ms
prism.on("beforealiascontextinit", function (ev, args) {
var timeout = 2000;
args.register(datasourceProviderFunction, globalAliasingProvider, timeout);
});
Mapping Object
The translation context is a simple JavaScript object which contains key value pairs for tables, columns,
hierarchies, formulas and custom item titles, all case-insensitive.
The sample below is a skeleton of a Mapping object that defines what metadata is to be translated and its new
value.
/**
* tables - aliases for table names
* "tables": {
* "table_name_1": "alias_1",
* "table_name_2": "alias_2",
* }
* columns - aliases for column names in scope of table
* "columns": {
* "table_name_1": {
* "column_name_1": "alias_for_column_name_1"
* "column_name_2": "alias_for_column_name_2"
* "column_name_3": "alias_for_column_name_3"
* },
* "table_name_2": {
* "column_name_1": "alias_for_column_name_1"
* "column_name_2": "alias_for_column_name_2"
* "column_name_3": "alias_for_column_name_3"
* }
* }
* titles - aliases for custom dimension titles, etc
* "titles": {
* "Custom title": "Alias",
* "Sample Revenue": "Sample Profit"
* },
* formulas - aliases for custom formula titles
* "formulas": {
* "Custom title": "Alias"
* },
* hierarchies - aliases for hierarchy titles
* "hierarchies": {
* "Custom title": "Alias"
* }
*/
var datasourceAliasing = {
"tables": {
"brand": "бренд",
"category": "категория",
"country": "страна",
"commerce": "коммерция"
},
"formulas": {
"Revenue": "Чистый доход"
},
"hierarchies": {
"Category by Brand and Age Range": "Категория через Бренд и Год"
},
"titles": {
"CUSTOM REVENUE": "ДОХОДЫ"
},
"columns": {
"Brand": {
"Brand": "Бренд",
"Brand ID": "Бренд Id"
},
"Category": {
"Category": "Категория",
"Category ID": "Id Категории"
},
"Widgets": {
"Revenue": "Чистый доход",
},
"Commerce": {
"Age Range": "Возрастные диапазоны",
"Brand ID": "Id Бренда",
"Category ID": "Id Категории",
"Condition": "Состояние",
"Cost": "Затраты",
"Country ID": "Id Страны",
"Date": "Дата",
"Gender": "Пол",
"Quantity": "Количество",
"Revenue": "Доходы",
"Visit ID": "Id Посетителя"
},
"Country": {
"Country ID": "Id Страны",
"Country": "Страна"
}
}
};
/**
* Global object example
* folder - aliases for folder names
* "folder": {
* "folder_name_1": "alias_1",
* "folder_name_2": "alias_2",
* }
* dashboards- aliases for dashboard names
* "dashboards- ": {
* "dashboard_name_1": "alias_1",
* "dashboard_name_2": "alias_2",
* }*
*/
var globalAliasing = {
"folders": {
"New Folder": "Folder renamed",
"my folder": "my folder renamed",
"Any name": "любое название"
},
"dashboards": {
"Sample - Ecommerce (1)": "Коммерческий Dashboard",
"Sample - Healthcare": "Sample Healthcare renamed",
"Sample - Healthcare (1)": "Healthcare renamed",
"my dashboard": "my dashboard renamed"
},
};
More Information
For more information on this topic, see the following Sisense Community articles: