AI OnAI Off
public class TestGlobalizationExamples
{
public TestGlobalizationExamples()
{
}
public void Test()
{
//Create a new page for swedish
PageReference newPageLink = GlobalizationExamplesHelper.CreateSwedishPage(Global.EPConfig.StartPage);
try
{
Global.EPDataFactory.GetPage(newPageLink,new LanguageSelector("EN"));
}
catch(LanguageNotFoundException)
{
//This will throw because we havent created english yet
}
// We will get the swedish page here, check returnedPage.LanguageBranch to be sure - it should contain "SV"
// The fallback scheme is configured in edit mode by the editor..
PageData returnedPage = Global.EPDataFactory.GetPage(newPageLink,LanguageSelector.Fallback("EN"));
//Create the new english version
GlobalizationExamplesHelper.CreateEnglishLanguageOnPage(newPageLink);
//This should now work as we have created a english version
PageData englishPage1 = Global.EPDataFactory.GetPage(newPageLink,new LanguageSelector("EN"));
//This code with fallback will now also return english
PageData englishPage2 = Global.EPDataFactory.GetPage(newPageLink,LanguageSelector.Fallback("EN"));
}
}
public class GlobalizationExamplesHelper
{
public static PageReference CreateSwedishPage(PageReference pageLink)
{
PageData newPage = Global.EPDataFactory.GetDefaultPageData(pageLink,1,new LanguageSelector("SV"));
newPage.PageName = "Swedish Test Page";
Global.EPDataFactory.Save(newPage,SaveAction.Publish);
PageReference newPageLink = new PageReference(newPage.PageLink.ID);
return newPageLink;
}
public static void CreateEnglishLanguageOnPage(PageReference pageLink)
{
PageData newPageLanguage = Global.EPDataFactory.CreateLanguageBranch(pageLink,new LanguageSelector("EN"));
newPageLanguage.PageName = "English Test Page";
Global.EPDataFactory.Save(newPageLanguage,SaveAction.Publish);
}
}
string[,] langs = EPiServer.Global.EPLang.AllLanguages();
for(int i = 0; i < langs.GetLength(0);i++)
{
EPiServer.Core.PageReference.AddQueryString(CurrentPage.LinkURL, "EPsLanguage", langs[0, i]);
}
This code is NOT verified, but it will hopefully get you started.
2) That's the way to go for sure.
3) EPiServer.Core.LanguageManager.GetContextLanguage()
/HAXEN
PageDataCollection pages = Global.EPDataFactory.GetLanguageBranches(CurrentPage.PageLink);
2) Sure, language branches in EPiServer 4.60 will always change the UI language if the language exists in the Lang-catalog.
3) A single class in 4.60 handles all language context related stuff, EPiServer.Core.LanguageContext..
== This is some raw material to one of the documents ==
How is do EpiServer know which language to display to visitors ?
The short story is that 4.60 will always enforce that the language is visible in the URL, either in the Path part or in the domain part of the URL. The reason is simple, search engines such as Google must be able to crawl a site and easily separate content. And users are expecting that they can cut and paste a link into a mail and send to a friend and that friend when clicking on the links will always get the same content. There are also some technical reasons such as outputcaching in .NET and web browser caching on the client that expects a single URL to be rendering the same content to anonymous users.
But, but..
Some scenarios..
Scenario 1: Global domain with multiple languages
You want all your visitors going to the offical site.com address but need to display different content depending on their language selection.
* Set a default language that most of your visitors will understand, normally english for a global site (EPsDefaultLanguageBranch in web.config)
* Activate language detection based on browser preference (EPfBrowserLanguageDetection in web.config)
* Add links or flags to the header or startpage that links to other languages (get the URL from PageData.DetermineAutomaticURL in the APi or Language drop down if you are using the Link Editor)
Testing the configuration:
Click on Tools->Internet options->Languages in Internet Explorer to select the language preference, the visit the site. You should be redircted to the correct language if you language selection can be matched to a site language.
Scenario 2: Local domains mapped to languages
There are two approaches to this depending on how you market your sites, one approach is to configure a site redirect at your hosting provider - for example redirecting http://site.se to http://site.com/sweden. The other approach that requires a bit configuration and is what is outlined below - you want http://site.se be the same as http://site.com/sweden but without the redirect.
* Add a configuration definition section in web.config, example: