Reputation: 961
I am trying to get the list of available languages for the current page in EPiserver. I currently have the following:
public static IHtmlString HrefLangLinks(this PageData currentPage)
{
IContentRepository repo = ServiceLocator.Current.GetInstance<IContentRepository>();
var pageLanguagesBranches = repo.GetLanguageBranches<PageData>(currentPage.ContentLink).ToList();
var availablePageLanguages = FilterForVisitor.Filter(pageLanguagesBranches).OfType<PageData>();
// Dictionary<String, String>
return null;
}
At the moment however availablePageLanguages
contains: {System.Linq.Enumerable.d__95}
How can I get a list of the names of the languages? For example de-DE, en-DE or de-AT ?
Upvotes: 0
Views: 1746
Reputation: 54
To get the available languages of a specific page, you can read the PageData.ExistingLanguages
property from your current page. That will give you an IEnumerable<CultureInfo>
result. And to get the language code from each CultureInfo
object, read the CultureInfo.Name
property.
The code would look like this:
currentPage.ExistingLanguages.Select(culture => culture.Name);
Upvotes: 1