|
Article relates to
|
Sitefinity 3.2 SP2 or later
|
|
Created by
|
Yasen & Rebecca
|
Question
What is the default behavior of Sitefinity with multiple language versions of pages and content items?
Answer
Localization in Sitefinity is possible at two levels: content items (i.e. when you set allowLocalization to true for Generic Content, News, Blog posts, etc.) and pages (when you set persistenceMode to PathPrefix or QueryString).
Basically, there are four main cases in which you can fall, designing an international website with Sitefinity:
1. Enabled page localization, enabled content localization.
2. Enabled page localization, disabled content localization.
3. Disabled page localization, disabled content localization.
4. Disabled page localization, enabled content localization.
When a page has an English and Greek version, for instance, you can add content items separately for both pages and those could be completely different. If you enable localization for Generic Content, however, in the Greek page you'll be able to use only Greek content items, and in the English page - only English items. Also, when editing the Greek page, in the Select shared content list, you only see the items that have a Greek version.
If page localization is enabled and content localization is not, when editing the Greek version of the page, you are able to choose from all shared content items, regardless of their language versions. However, if you use new content that is not shared, it is displayed in the current page version only, as the other language versions of the page are in fact completely different pages.
If you have an English page and no corresponding Greek version is created, you'll always see the English version, regardless of the localized content.
In other words, when you access http://yoursite.com/en/page.aspx or http://yoursite.com/el/page.aspx, you see the same page as there is only one existing page. If localization for Generic Content is turned off, you'll see the shared content you added, whatever the language is. On the other hand, if the content is localized, you'll see the English version in the first URL and the Greek version in the second URL. This is the default behavior.
Since the release of version Sitefinity 3.2 SP2 there is an option to display a particular language version of the page only and throw an error when this language version doesn't exist.
To achieve this, you need to set useStrictLanguageVersions to true in the application web.config:
| <cms defaultProvider="Sitefinity" |
| pageExtension=".aspx" |
| disabled="false" |
| useStrictLanguageVersions="true" |
| pageEditorUIMode="Overlay"> |
| <providers> |
| |
Thus, when http://yoursite.com/el/page.aspx is accessed and there isn't a Greek version of page.aspx, an HTTP error 404 is thrown. However, in page preview mode (http://yoursite.com/el/page.aspx?cmspagemode=preview), the content will be displayed in the default language.
The default error message is: “Invalid Page language version request! The requested page does not contain a definition for the requested language.”
You can also create a custom error page, e.g. ~/Sitefinity/NoLanguageVersion.aspx, and edit the web.config as shown below.
| <customErrors mode="RemoteOnly"> |
| <error redirect="~/Sitefinity/NoLanguageVersion.aspx" statusCode="404" /> |
| </customErrors> |
You can handle the error further in the Global.asax.
| void Application_Error(object sender, EventArgs e) |
| { |
| Exception ex = Server.GetLastError(); |
| if (ex is HttpException) |
| { |
| Telerik.Cms.Exceptions.NoPageLanguageVersionHttpException httpEx = ex.InnerException as Telerik.Cms.Exceptions.NoPageLanguageVersionHttpException; |
| if (httpEx != null |
| && httpEx.GetHttpCode() == 404 |
| && httpEx.Source.StartsWith("Telerik.Cms") |
| && httpEx.Message.StartsWith("Invalid Page language version request!")) |
| { |
| // Get requested page |
| //Telerik.Cms.ICmsPage page = httpEx.Page; |
| |
| Response.Redirect("~/Sitefinity/NoLanguageVersion.aspx"); |
| Response.End(); |
| } |
| } |
| } |