When you are implementing websites in .Net based Umbraco CMS system you have the option to code your templates in C# based Razor templates. Some bits and pieces can be useful to know about. I will post such useful small tips on my blog.
Get the country information
The .NET framework has great support for global languages, so a good place to start to get information about the current page is to retrieve an instance of the TextInfo. From there you can get for instance the “CultureName”, which on my page is “da-DK”.
System.Globalization.TextInfo textinfo = Model.CurrentCulture.TextInfo; @textinfo.CultureName // For instance da-DK
You may for instance get the following:
textinfo.ANSICodePage: 1252 textinfo.CultureName: da-DK textinfo.EBCDICCodePage: 20277 textinfo.IsRightToLeft: False textinfo.LCID: 1030 textinfo.ListSeparator: ; textinfo.OEMCodePage: 850
In my case I just needed a lowercase of the language code, which can be extracted from the CultureName. I can be done in many ways, but here is the way I did it:
System.Globalization.TextInfo textinfo = Model.CurrentCulture.TextInfo; string langCountry = textinfo.CultureName.ToLower().Split('-'); string countryCode = langCountry; // is dk