How to retrieve a list of all enabled languages for the EPi Server website programmatically?
Asked Answered
H

2

6

I simply want to get a list of all enabled languages for the EPi Server website (enabled in the "Manage Website Languages" panel in Admin mode) and preferably also be able to retrieve the path to the flag icon and of course the culture name/ID.

I'm using EPiServer 6 R2 so if the code works for that version it would be lovely. Pointing me in the right direction would be great too.

Higinbotham answered 15/10, 2013 at 7:40 Comment(0)
M
8

In EPiServer.DataAbstraction you have LanguageBranch.ListEnabled().

Take a look at this file to see how it's bound in Admin mode: C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Application\UI\CMS\Admin\EditLanguageBranches.aspx

Maccaboy answered 15/10, 2013 at 13:14 Comment(2)
Note: Not the answer to your question but you could look at the start page like this instead to find the languages available, it's usually translated to all languages: PageDataCollection languagesForCurrentPage = EPiServer.DataFactory.Instance.GetLanguageBranches(PageReference.StartPage);Maccaboy
Cheers. The method EPiServer.DataAbstraction.LanguageBranch.ListEnabled() did exactly what I was looking for. I'll mark your question but please also update the questionHiginbotham
M
13

You mean

ServiceLocator.Current.GetInstance<ILanguageBranchRepository>().ListEnabled();

However you should really not be using the ServiceLocator at all and instead take a ILanguageBranchRepository as a constructor parameter that will be automatically resolved by StructureMap. This gives your class a clear list of its dependencies and makes unit testing it a lot easier as you don't have to mock the ServiceLocator.

Mulvey answered 18/6, 2015 at 8:12 Comment(1)
True, but the question regarded EPi6 which doesn't implement the servicelocatorMuseology
M
8

In EPiServer.DataAbstraction you have LanguageBranch.ListEnabled().

Take a look at this file to see how it's bound in Admin mode: C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Application\UI\CMS\Admin\EditLanguageBranches.aspx

Maccaboy answered 15/10, 2013 at 13:14 Comment(2)
Note: Not the answer to your question but you could look at the start page like this instead to find the languages available, it's usually translated to all languages: PageDataCollection languagesForCurrentPage = EPiServer.DataFactory.Instance.GetLanguageBranches(PageReference.StartPage);Maccaboy
Cheers. The method EPiServer.DataAbstraction.LanguageBranch.ListEnabled() did exactly what I was looking for. I'll mark your question but please also update the questionHiginbotham

© 2022 - 2024 — McMap. All rights reserved.