简体   繁体   中英

How to localize SharePoint publishing page title

How does one localize the page title of a SharePoint publishing page? I am provisioning it like:

PublishingPage newPage = publishingWeb.GetPublishingPages().Add("mypage.aspx", "mylayout.aspx");
newPage.Title = "$Resources:MYRESX,MyPage_PageTitle";
newPage.Update();

When I provision this page, the title shows up literally, $Resources:MYRESX,MyPage_PageTitle , instead of SharePoint looking up the string. So, I guess my assumption is wrong that SharePoint would look the string up. Or I have the syntax wrong.

I am already referencing MYRESX in other places; I am sure the resource file / string is accessible.


I have the exact same issue for webpart titles as well, so hopefully a unified solution exists for both scenarios.

Try SPUtility.GetLocalizedString :

newPage.Title = 
    SPUtility.GetLocalizedString(
        "$Resources:MyPage_PageTitle", 
        "MYRESX", 
        web.Language);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM