Get member description in user's culture code

MarcusH
Contributor III

Does anyone know how to get the member description in the user's culture code?

1 ACCEPTED SOLUTION

ChristianW
Valued Contributor

ok, you can access the descriptions with the memberinfo object:

 

Dim MemberIdOfAccount As Integer = BRApi.Finance.Members.GetMemberId(si, DimTypeId.Account, "41010")
Dim test As MemberInfo = BRApi.Finance.Members.GetMemberInfo(si, DimTypeId.Account, MemberIdOfAccount,,,New MemberDisplayOptions(True,"en-US",True,False,False,False,False,0))

BRApi.ErrorLog.LogMessage(si, test.Descriptions("en-US").Description & " " & test.Descriptions("fr-FR").Description)

 

View solution in original post

17 REPLIES 17

ChristianW
Valued Contributor

Hi Markus

Do you need to know, how to load it? Or how to access it?

Cheers

Christian

How to access it. I am processing base members for Confirmation Rules and I want to show the user the member description in their language if it fails the Rule. I am currently using this to get the member list

Dim AllBase As List(Of Member) = api.Members.GetBaseMembers(BRApi.Finance.Dim.GetDimPk(si, UD6DimensionName), topUD6MemberID)

wnindl
New Contributor III

Christian, I would love to learn how to load local descriptions.  With all the posts on this thread I am totally able to access and now to translate.
Thanks/Danke/Merci/Gracias/Grazie 

ChristianW
Valued Contributor

ok, you can access the descriptions with the memberinfo object:

 

Dim MemberIdOfAccount As Integer = BRApi.Finance.Members.GetMemberId(si, DimTypeId.Account, "41010")
Dim test As MemberInfo = BRApi.Finance.Members.GetMemberInfo(si, DimTypeId.Account, MemberIdOfAccount,,,New MemberDisplayOptions(True,"en-US",True,False,False,False,False,0))

BRApi.ErrorLog.LogMessage(si, test.Descriptions("en-US").Description & " " & test.Descriptions("fr-FR").Description)

 

Thank you! 

JackLacava
Community Manager
Community Manager

BRApi.Finance.Members.ReadMemberDescriptionsNoCache(si, dimTypeId, memberId) should give you all the descriptions, then you can loop through them. Each MemberDescription has a MemberDescriptionPK with a property for the language, i think.

Dim MemberIdOfAccount As Integer = BRApi.Finance.Members.GetMemberId(si, DimTypeId.Account, "41010")
Dim list As List(Of MemberDescription) = BRApi.Finance.Members.ReadMemberDescriptionsNoCache(si, dimTypeId.Account, MemberIdOfAccount)
Dim englisch As String = list.FirstOrDefault(Function(x) x.MemberDescriptionPk.Language = "en-US").Description
Dim french As String = list.FirstOrDefault(Function(x) x.MemberDescriptionPk.Language = "fr-FR").Description
BRApi.ErrorLog.LogMessage(si, englisch & " " & french)

wnindl
New Contributor III

I love 'Dim englisch'. Endlich ein Tip in Deutsch!
But seriously, thank you so much for the tip. Exactly what we need to derive local account descriptions.

wnindl
New Contributor III

Thanks again for these posts.  I got the list function to work perfectly.

Do we also have a function that can write to MemberDescription? 
I am researching the possibility of a 'translation function' to take in English, translate (with Google API, and write back to German Description (or any other language.

MarcusH
Contributor III

In answer to your question I think the function SaveMemberInfo is what you want. The MarketPlace app AST has an example in Dashboard Extenders (sorry I can't remember what AST stands for). And it is also mentioned here but that is updating the security group not the member description.

However I looked at doing the same a while back and I realised that it was not going to work how I wanted. Firstly I needed to buy a licence of some sort to use Google for multiple requests like that (a single call is OK) and secondly who was going to review the translations and how. English has so many different meanings for the same word (off the top of my head I can think of 2 meanings for Account and 3 for Gross). Another aspect you need to consider is that this is just handling the member descriptions and does not include report names, cube view text, dashboards, confirmation rules etc. I decided that the best option (for me and my client at least) was to manage the translations in Excel and allow native speakers to review the translations. Then export that to XML and load it.

It is really simple to get Excel to translate text. I documented how you can update the other aspects of the application (ie XFStrings): here 
There is a link to an Excel spreadsheet that imports and exports XML files for the XFStrings values. Also on the blog is a metadata manager which is a front-end for application XMLs. Those two pages should get you started on putting together something in Excel for translating and reviewing foreign languages if you decide to go down the Excel route.

 

Awesome stuff! You have one more subscriber 😎

wnindl
New Contributor III

Thanks Marcus,
I am using SaveMemberInfo but could not (yet) find a way to write to the local descriptions.  Just a little more trial and error necessary.  For now i am writing to 4 text members and than some lucky analysts will have to copy by hand unless i find a solution before New Year.

To the Google Translate API:
I probably ran the code some 10000 times last evening and it worked.  I found this code by accident here:
Source: https://www.vbforums.com/showthread.php?883767-Translate-text-with-Google-Translation-and-VB-NET

Code:

Public Shared Function gtranslate(ByVal inputtext As String, ByVal fromlangid As String, ByVal tolangid As String) As String
	inputtext = HttpUtility.HtmlAttributeEncode(inputtext)
	Dim step1 As New WebClient
	Dim step2 As String = step1.DownloadString("https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=" & tolangid & "&hl=" & fromlangid & "&dt=t&dt=bd&dj=1&source=icon&q=" & inputtext)
	Dim step3 As Newtonsoft.Json.Linq.JObject = JObject.Parse(step2)
	Dim step4 As String = step3.SelectToken("sentences[0]").SelectToken("trans").ToString()
	Return step4
End Function

I am calling it like so:

Dim deDescr As String = gtranslate(enDescr, "en", "de")
Dim frDescr As String = gtranslate(enDescr, "en", "fr")
Dim esDescr As String = gtranslate(enDescr, "en", "es")
Dim itDescr As String = gtranslate(enDescr, "en", "it")

I have the whole thing in an Extensibility rule at the moment and run it from a data management step (first for a small part of the account hiearchy and then over the whole Balance Sheet or Income Statement).
And you are of course correct, it might lead to some really funny translations. At least in German but those are relatively easy correct.  Just need my french, italian, and spanish friends to help with the other translations.

And thanks for the link on strings.  will study that right now.  
enDescr is either then English description, or the local if i dont have one yet, or the member name (only tested with account dimension up to now).

wnindl
New Contributor III

Marcus,
Had to add another response:
Thank you so much for the link to your website.  I have a rudimentary multi-language app (actually several) and I could not agree more that multi-language error messages might be even more important than multi-language buttons and headers.
Anyway, I am now implementing your 'get user's cultur code'. I took the easy route and added a drop down to my dashboards which sells really nicely as i can switch languages and the whole page changes.
Testing your XFString manager over the weekend. Thank you so much for sharing. I always thought of going against the XML but have not taken the time to research.

ReadMemberDescriptionNoCache returns the list of aliases for the member (I've just tested it). If the member does not have an alias for a particular language it does not return anything. MemberDisplayOptions on the other hand returns the alias if it exists and the default value if there is no alias for the member which is what I want. Thank you for your time Jack. I will keep this in my little Rules bank.

ChristianW
Valued Contributor

Markus, you can use Jack's suggestion as well, I tested it and added a sample.

An hour ago I didn't know how to do it. Now I don't know which piece of code to use! Thank you Christian.

ChristianW
Valued Contributor

In the second sample the default is null and without a description it will create an error. You can code around it, but the first solution seams to be less complicated.