Friday, November 28, 2014

get TermSet Name (Label) by language (LCID)

today is a small story of how i won MS :)

well i decided i want to make a custom navigation based on MMD, and with the site being with variations i need to be able to decide witch language i need.

with Terms its pretty easy, you defauld method "GetDefaultLabel" accepts LCID, but with TermSet it just brings you the default language on the server, if the TermSet has one.

finally i got help from my best friend, System.Reflection, and this is the code:

Dictionary<int, string> names =
    System.Reflection.BindingFlags.NonPublic | 
    GetValue(ts) as Dictionary<int, string>;
string label = names.Where(n => n.Key == lcid).First().Value;