Login

Updating multi language pages manually

Versions: 4.30 - 4.51, FAQ number: 136, Old FAQ number: 3840
Note: This faq does not apply to the globalization support in version 4.60 and later!

 

Updating a multi language page from code

Updating a multi language page from code differs quite alot depending on what version of EPiServer you are running under. In EPiServer 4.50 the multi language runtime handles versions and languages so you don't have to worry about anything except filling the properties for the page. In previous versions this has to be handled manually. We will give examples of how to update your page below.

Before loading a page that you want to update you should be aware of how the property "LoadRawPageData" on a PageReference works. If LoadRawPageData is set to true then the only thing the multi langauge runtime will do when loading the page is to set Pagename and status for the page depending on what language the page is loaded with (this is described in the multi language tech note). If the property is set to false the page will be translated into the language that should be loaded (or another language following the rules for default language and language fallback).

If you only want to change one language then you could either load the page with LoadRawPageData set to true and access the language specific properties directly (ie page["MyProperty___EN"] = someValue) . You could also load the page with LoadRawPageData set to false and alter the value for the property on this form: ["MyProperty"] = someValue which would then change the value for MyProperty___EN is the page was loaded in English.

Below we will describe how to update the page for several languages depending on what version of EPiServer you are running under:

EPiServer 4.50 and later

In EPiServer 4.50 the multi language environment detects if changes has been done for several languages. This means you only have to save the page once and a version will be created for each language that has been changed (including common properties). This sample code illustrates how the multi langauge page with id 244 is updated for several languages:

public static String Execute()
  {
   PageReference pageToAlter = new PageReference(244);
   pageToAlter.LoadRawPageData = true;

   PageData page = EPiServer.Global.EPDataFactory.GetPage(pageToAlter);

   String currentPageName = (String)page["PageName___EN"];
   String suffix;

   if(currentPageName.IndexOf("English") != 0)
    suffix = "1";
   else
   {
    suffix = currentPageName.Substring(7);
    suffix = (Int32.Parse(suffix) + 1).ToString();
   }
    
   page["PageName___EN"] = "English" + suffix; 
   page["PageName___SV"] = "Swedish" + suffix; 
   page["PageName___NO"] = "Norwegian" + suffix;
   page["WriterName"]  = "Common" + suffix;

   EPiServer.Global.EPDataFactory.Save(page, SaveAction.Publish, AccessControlList.NoAccess);

   return "Page " + pageToAlter.ID.ToString() + " was updated for all languages";
  }

EPiServer 4.41 and previous

In earlier versions of EPiServer this is a bit trickier. The following example code demonstrates how it's possible to update several languages for a page with a scheduled job:

public static String Execute()
  {
   PageReference pageToAlter = new PageReference(138);
   pageToAlter.LoadRawPageData = true;

   PageData page = EPiServer.Global.EPDataFactory.GetPage(pageToAlter);

   String currentPageName = (String)page["PageName___EN"];
   String suffix;

   if(currentPageName == null || currentPageName.IndexOf("English") != 0)
    suffix = "1";
   else
   {
    suffix = currentPageName.Substring(7);
    suffix = (Int32.Parse(suffix) + 1).ToString();
   }
    
   page["PageName___EN"] = page.PageName = "English" + suffix;   
   page.LanguageID = "EN";
   EPiServer.Global.EPDataFactory.Save(page, SaveAction.Publish, AccessControlList.NoAccess);   
   
   page = EPiServer.Global.EPDataFactory.GetPage(pageToAlter);
   page["PageName___SV"]= page.PageName = "Swedish" + suffix;
   page.LanguageID = "SV";
   EPiServer.Global.EPDataFactory.Save(page, SaveAction.Publish, AccessControlList.NoAccess);
   
   
   page = EPiServer.Global.EPDataFactory.GetPage(pageToAlter);
   page["PageName___NO"] = page.PageName = "Norwegian" + suffix;
   page.LanguageID = "NO";
   EPiServer.Global.EPDataFactory.Save(page, SaveAction.Publish, AccessControlList.NoAccess);

   page = EPiServer.Global.EPDataFactory.GetPage(pageToAlter);
   page["WriterName"]  = "ChangeCommon";
   page.PageName = MultiLanguageRuntime.CommonName;
   page.LanguageID = MultiLanguageRuntime.COMMONLANGUAGEID;
   EPiServer.Global.EPDataFactory.Save(page, SaveAction.Publish, AccessControlList.NoAccess);

   return "Page " + pageToAlter.ID.ToString() + " was updated for all languages";
  }

 

Notice the rows where the name for the page is set (   page["PageName___NO"] = page.PageName = xxxxx). The name of the page is set automaticly in version 4.50 but in 4.41 you has to set both the language name property and the page name.

EPiTrace logger