sitecoresitecore6sitecore8sitecore-mvcsitecore7.2

Language.TryParse Method use in sitecore point of view?


Just to ask one things.

What is the use of below methods in sitecore context.

Language.TryParse(string value, out bool);

As this method belongs to Sitecore.Kernal library so not able to see the code however in my case it's not working as expected.


Solution

  • You're referring to the bool Language.TryParse(string value, out Language result) method, right? It'll give you a Language object if the provided value is a locale, such as en-US, registered in Sitecore. There are some more caveats within that method. You can read the source of it using a reflection tool, such as dotPeek.

    Since there may be different languages in different Sitecore databases, it's usually more suitable to use for example LanguageManager.GetLanguage(string name, Database database). It'll return the Language object if exists, or null if it's not available in the given database.