using i18n Texts for VizFrames DimensionDefinition and MeasureDefinition

Viewed 334

I am using a pie chart vizFrame and want to make it translateable.
--> i18n texts
In the API Reference for MeasureDefinition and DimensionDefinition is written

name : Name of the measure as displayed in the chart

So name is the property that decides how my Measure and Dimension are named.
If I use a hard string it works.
If I use an i18n text it doesnt.
I think it is because the values Property of the FeedItem seemingly needs to be the same as the name Property Measure and Dimension. But thats only a guess from what I see in Samples of the Demo Kit...

Does anyone know how I can use i18n texts in the VizFrame?

Code:

<viz.data:dimensions>
    <viz.data:DimensionDefinition name="{i18n>material}"
        value="{odataModel>MaterialText}" />
</viz.data:dimensions>
<viz.data:measures>
    <viz.data:MeasureDefinition name="{i18n>sales}"
        value="{odataModel>Sales}" />
</viz.data:measures>

Error:

Uncaught (in promise) Error: "sales" is of type string, expected any[] for property "values" of Element sap.viz.ui5.controls.common.feeds.FeedItem#__item4

2 Answers

Well, one way could be to use factory for the corresponding aggregation. In the factory you can clone some template item and instead of binding text, you could dynamically assign 'hard' one, e.g:

myDimensionFactory: function(sId, oContext){
    const oBundle = this.getModel('i18n').getResourceBundle();       
    return this.byId('templateItemId').clone(sId)
               .setName(oBundle.getText('sales'));
                   //or whatever you need translated, 
                   //you can also use oContext if you want to translate something from the model
}

You are right about the FeedItem. The property values has to match your dimensions/measures.

Here is how you can pass your translatable text as an array of strings and not just a simple string (using a trick aka ExpressionBinding):

<viz.feeds:FeedItem uid="..."
    type="Dimension"
    values="{= [${i18n>material}] }" />

After this the error message should be gone and your chart will contain a translated axis label

You can even invoke formatters this way

<viz.feeds:FeedItem uid="valueAxis"
    type="Measure"
    values="{= [${ path: 'viewModel>/propertyOfViewModel', formatter: 'Formatter.formatStuff' }] }" />
Related