SuperOffice multi language support workaround

1 post / 0 new
Anders
Anders's picture
SuperOffice multi language support workaround

Business Analyze 4 Analysis with Analyze SuperOffice content package does not support SuperOffice multilanguage strings.

The format of the multilanguage strings are

[CountryCode]:"Localized String";[CountryCode]:"Localized String".

For example:

[US]:"This is the english text";[NO]:"Dette er den norske teksten"

 

 

 

When creating dashboards with elements that has SO Multilanguage strings the result can be quite ugly since the entire string will be displayed.

You can always use BA Scripting Engine =eval(); function to decode and pick out the string you want displayed by placing the below script in the column Expression field.

The =eval(); function lets you execute JavaScript (actual MS JScript) code placed inside the function call (input).
Refer to Scripting Engine Expression tester inside the system administration menu for a quick reference or the Developers Guide for more details on the =eval(); function.

We recomend placing this script in the column expression at DataCentral DataTable level since this expression will be applied to DataElements/Visualizations when used on dashboards.

NOTE!  When using SE Expressions like this one, always turn off column formatting on visualizations by setting format to "None" in edit column dialog.

 

Given the column name [columnName] and the desired output as US-text strings you can deploy this script:

=eval(if('[columnName]'.match(/US:\"[^\"]+\"/g)){'[columnName]'.match(/US:\"[^\"]+\"/g)[0].split(/\"/)[1]}else{'[columnName]'});

Replace [columnName] with your actual column name in square brackets.
If you want to get other language strings than US, replace the text US in both the if-statement and in the acutal regex expression inside the if-statement.

About the script

If we break down the script into lines of code it is easier to see what the script does:

=eval(
      if('[columnName]'.match(/US:\"[^\"]+\"/g)){
            '[columnName]'.match(/US:\"[^\"]+\"/g)[0].split(/\"/)[1]
      }else{
            '[columnName]'
      }
);

First we have a if-statement which uses regular expressions to check wheter this string actually contains a US specific section in the format of a SO multilanguage string.
If we actually find a section formatted as 'US:"US text string" in the column, the expression inside the if-statment evalutes to true (not undefined actually) and the first code block is executed:

This code block uses a regular expression to get the first match of the US specific text.

If the column has this text: '[NO]:"Norwegian text";[US]:"US text"' the regular expression will return [US]:"US text"

Since we only wants to get the actual text we append a split-function to the expression which splits the string into an array devided by the double quote character.
By now we have an array like this one:

[0] -> [US]:"
[1] -> US text
[2] -> "

By referencing the second item (index= 1) we get exactly the text string that we want which is the text that the entire expression returns in that case.

If we cannot find a section formatted as 'US:"US text string" in the column, the expression inside the if-statment (if-statement expression evaluates to undefined), the else block in the if-statement is executed which just returns the column text plain and simple.

The reason why we want to test whether the US language string exists before trying to get it is because not all text strings in the column have to be multilingual

 

Further cusomizations

If your Business Analyze users uses different languages you might want the returned language to differ based on logged on user?

The script expression =u(locale); will return the locale of the logged on user but this is the language (en-gb etc) and not the country code (US).

To be able to customize the country you can place the country code on a ba user more field (for example =u(ext6t); ) or create a system variable (for example =sv(countryCode); ) to hold the country code.

We would recomend using a system variable for this purpose since the system variable always has its system state but can be overridden on user, group or orgunit level.

The above script rewritten using a hypotetic system variable named countryCode woud be like this:

=eval(if('[columnName]'.match(/=sv(countryCode);:\"[^\"]+\"/g)){'[columnName]'.match(/=sv(countryCode);:\"[^\"]+\"/g)[0].split(/\"/)[1]}else{'[columnName]'});

ATTN! Rembember that Scripting Engine does not support line breaks in version 4!

 

Happy coding!