Page name in selected language


This should be easy: I retrieve a PageData object in a specific language via the content repository. Now I would like to display the name of the page in that specific language. How do I get this page name? I have tried using PageName, but this propery returns the page name in the master language.

var pd = ServiceLocator.Current.GetInstance().Get(pageId, new LanguageSelector(language));
var displayName = pd.PageName // this returns the name in the master language
May 15, 2015 13:22

Which EPiServer version are you using (suspicios looks LanguageSelector)? Can't recall in which version was that used. Just tested in 8.x -> PageName contains correct (translated) name of the page.

May 16, 2015 23:02

Hi Esben,

Maybe you are loading page for specific version, where there is no language branch. Try to use ToReferenceWithoutVersion extension method.

var pd = ServiceLocator.Current.GetInstance<IContentRepository>().Get<PageData>(pageId.ToReferenceWithoutVersion(), new LanguageSelector(language));

If this wont help, then you could try to load the page and debug what language and what languageBranch was loaded. Also load all available language branches for the page.

var pd = ServiceLocator.Current.GetInstance<IContentRepository>().Get<PageData>(pageId, new LanguageSelector(language));
var displayName = pd.PageName // this returns the name in the master language

 var language = pd.Language;
 var branch = pd.LanguageBranch;

var languageBranches = ServiceLocator.Current.GetInstance<IContentRepository>().GetLanguageBranches<PageData>(new pageId);
foreach (var languageBranch in languageBranches)
May 17, 2015 20:11

Hi Valdis and Grzegorz

I am using 7.5. Grzegorz pointed me in the right direction with the remark about loading a page for a specific version. In turned out, that I had loaded a version where the page name wasn't translated, so it still appeared in the master language. I used an instance of IContentVersionRepository to get the newest version, and now the page name is translated.

Thank you both for sharing your ideas!

May 19, 2015 10:59
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.