cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve Multilingual text for a Attribute

pankaj001
Participant
0 Kudos

Hi Experts,

Can someone please help me in retrieving the multilingual string for a attribute of Taxonomy table.

Regards,

Pankaj

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Pankaj,

There are two possible ways to achieve this:

1. When creating a user context use the region that you want to present the values in like so:

         

new UserSessionContext("MDSName", "RepositoryName","Region", "UserName");

where "Region" is replaced by the wanted region(i.e. French [FR], English [US], etc.)

Now you can use the method

com.sap.mdm.extension.data.RecordEx.getAttributeDisplayValue(FieldId taxonomyFieldId, AttributeId attrId, int regionalLayer)

With the needed regionLayer (CURRENT, INHERITED or PRIMARY_INHERITED – notice that CURRENT will return null if no value exists in the chosen language).

This method returns an array of strings (in case it's a multi value attribute) that are the attribute's value(s) in the language you used when creating the session context.

Check the method's Javadoc for more info.

2. Log in with any language and use the MdmValueFormatter class to get to the required value like in this code snippet:
 


RetrieveLimitedRecordsExCommand retCom= newRetrieveLimitedRecordsExCommand(context);

retCom.setResultDefinition(resultDefinition);

retCom.setSearch(search);

retCom.execute();

//In this instance I retrieved only one (known) record here

RecordEx record = (RecordEx) retCom.getRecords().getRecord(0);

//The (Categories table)record that is pointed to by the lookup field value

Record[] lookupRecord = record.findLookupRecords(categoryFieldId); 

RetrieveAttributeLinksCommand attrLinksCom = new RetrieveAttributeLinksCommand(context);

attrLinksCom.setTaxonomyTableId(_repositorySchema.getTableId("CATEGORIES"));

attrLinksCom.setRecordId(lookupRecord[0].getId());

attrLinksCom.execute();

AttributeProperties[] attributeProps = attrLinksCom.getAttributes();

/* This creates the French [FR] region properties, for runtime usage you can either 1. use UserSessionContext.getRegion() if you logged in with

* the needed language,

* 2. Prepare an enum of the locales used in your repository (easiest and best way to preserve performance)

* 3. Use  GetRepositoryRegionListCommand to get all of the regions in your repository and use the one you need according to the region code.

*/

RegionProperties frRegion = new RegionProperties("French [FR]", Locale.FRENCH, "fre___");

for(int atrId=0; atrId<attributeProps.length; atrId++){

       //Gets the value from the current attribute according to index atrId

       MdmValue attrVal = record.getAttributeValue(categoryFieldId, attributeProps[atrId].getId());

       //Uses MdmValueFormatter helper class to format the value so that it appears in the language defined by the region supplied

       String[] formattedValues = MdmValueFormatter.formatAttributeValue(attributeProps[atrId], attrVal, frRegion,

                                                MetadataManager.getInstance().getRepositoryDimensions(context));

}

Now String[] formattedValues will contain all of the values(if multi valued, only one if not) of this attribute in the language specified.

Regards,

Dan.

pankaj001
Participant
0 Kudos

Hi Dan,

Thanks a lot for your response

Do we need to use first 3 characters for all the region code? for eg. "ger___" for German .... "chi___" for Chinese?

Regards,

Pankaj

pankaj001
Participant
0 Kudos

Hi Dan,

How can we format the text for Attribute name. Below is the code to retrieve the Attribute Name.

attributeProps[a].getName().get("chi___");

Where attributeProps is the list of all the attribute. I am getting "????" as the output. How can i format these text in Chinese?

Thanks a lot for your help!

Regards

Pankaj

Former Member
0 Kudos

Hi Pankaj,

Yes, you need to use the language codes as you described (i.e. "ger___" - notice there are 3 underscores "_").

On the other hand you can use commands such as

GetRepositoryRegionListCommand and GetRepositoryInheritedRegionListCommand

to get the regions you need from the repository in runtime.

Former Member
0 Kudos

Hi Pankaj,

Getting strings such as "?????" in the console has to do with the encoding you use for your application in eclipse (it should show ok in your browser - if you have the relevant fonts installed).

To enable eclipse to show character sets other then ASCII you need to :

1. go to "Run Configuration" for your app (press the dropdown menu next to the green "play" button to see it).

2. navigate to the "common" tab (the last one)

3. under "Encoding" choose "other" and in the drop down choose "UTF-8"

here is a screen from my machine after I did it:

Best Regards,

Dan.

pankaj001
Participant
0 Kudos

Hi Dan,

I cannot find "Encoding" under Common Tab of Run Configuration. I am using NWDS 7.01.05.

Please suggest.

Regards,

Pankaj

Answers (1)

Answers (1)

pankaj001
Participant
0 Kudos

Hi,

I need to retrieve the values in all the available languages(multilingual) for a attribute from Taxonomy table via Java API. Can anyone please provide me some helpful pointers. I am able to retrieve attribute value only in  English[US].

Regards,

Pankaj