Export Functions for Translations
When creating export definitions in Reflex Blue, it is possible to export translations of data that can be translated via the export script. Entities with data that can be translated have two extension functions that can be used to request translations.
Translate function
The Translate function returns the translation of the specified field in the specified language for the entity on which it is used.
Definition
string Translate(string fieldName, string languageIdentification) Parameters
| Name | Description |
|---|---|
fieldName | This is the name of the field in the entity that can be translated. |
languageIdentification | This is the Identification of the language for which you want to request the translation. |
Return value
The translation in the specified language in text format.
Example
Suppose you have access to an article in your export script (via an article variable) and you want to retrieve the translation of the article name in German, you can use the following syntax:
article.Translate(nameof(article.Name), "DUITS"); TranslateOrDefault function
The TranslateOrDefault function returns the translation of the specified field in the specified language for the entity on which it is used. If there is no translation available, the default value specified is returned.
Definition
string Translate(string fieldName, string languageIdentification, string defaultValue) Parameters
| Name | Description |
|---|---|
fieldName | This is the name of the field in the entity that can be translated. |
languageIdentification | This is the Identification of the language for which you want to request the translation. |
defaultValue | This is the value returned if there is no translation available. |
Example
Suppose you have access to an article in your export script (via an article variable) and you want to retrieve the translation of the article name in German, and get the text No translation if a translation is missing, you can use the following syntax:
article.Translate(nameof(article.Name), "GERMAN", "No translation"); In a complete export script, the usage of the Translate and TranslateOrDefault extension functions for translations could look like this:
@using ReflexNG.ImportsExports.Domain.Templating.Formatters
@using ReflexNG.Articles.Domain
@inherits ReflexNG.ImportsExports.Domain.Templating.Articles.ArticlesExportTemplate
@{
var csvOptions = CsvOptions.Default.WithSeparator(';');
await foreach (var article in Model.Articles)
{
WriteCsv(
csvOptions,
Formatter.Create(article.Code),
Formatter.Create(article.Name),
Formatter.Create(article.Translate(nameof(article.Name), "GERMAN")),
Formatter.Create(article.TranslateOrDefault(nameof(article.Name), "ENGLISH", article.Name))
);
}
} In the above example of a minimal export script for articles, all articles are exported in CSV format with their Code, Name, and the translations of the Name in German and English. If there is no translation available for the Name in English, the default value of the Name is used. The content of the exported CSV file could look like this:
1;Zoutvlees;Salzfleisch;Salt meat
2;Kip;Huhn;Kip