Localization

Localization with Kooboo CMS is not as trivial as in other CMS like Sitecore, but it works. The most complicated part is to change the language by staying on the same page.

The idea is to create a primary site (first language) and sub-sites for others. Unfortunately, it seems impossible to simply find the page of an other site/subsite, it is necessary to ensure that all sub-sites have the same structure as the base site.

CAUTION: Do not do "Unlocalize" on a page, it seems to completely break down the structure of the subsite where the operation is performed, then you must rebuild this page and its sub pages by hand. Also, once a page is localized, the child added to the parent site does not automaticly appear anymore on the subsite. So the location is not "easy" as the initial creation of the site, after the creation of the site you end up having to recreate everything by hand.

Here is my sample code to switch from one language to another.

  @{
var enSite = "/en";
var page = Html.FrontHtml().PageContext.PageRequestContext.Page;
var site = Html.FrontHtml().PageContext.PageRequestContext.Site;
var prefix = Url.FrontUrl().PageUrl(page.VirtualPath).ToString();
if (!string.IsNullOrEmpty(prefix)) {
if (prefix.EndsWith(page.VirtualPath)) {
prefix = prefix.Substring(0, prefix.Length - page.VirtualPath.Length);
}
var newBasePath = site.Parent == null ? prefix + enSite : prefix.Substring(0, prefix.Length - enSite.Length);
var pagePath = (newBasePath + "/" + page.VirtualPath).Replace("//","/");
<p class="navbar-text change-lang navbar-right">
<a href="@pagePath">@(site.Parent == null ? "English" : "Français")</a>
</p>
}
}