Try our conversational search powered by Generative AI!

Page name in selected language

Vote:
 

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
#121624
May 15, 2015 13:22
Vote:
 

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.

#121641
May 16, 2015 23:02
Vote:
 

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)
{
}
#121671
May 17, 2015 20:11
Vote:
 

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!

#121871
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.