Alternating a Translated Homepage Layout

Topics: Localization, Writing themes
Oct 21, 2011 at 6:38 PM
Edited Oct 21, 2011 at 6:39 PM

After translating a page to another language we end up with two seperate slugs, one for the default language "~/" and then a seperate ones for each translation, i.e. - ~/home-zh-CN, ~/home-es-MX, etc ...

The problem that arises is when we try to alternate the layout for what we're calling the "HomePage", as in "Layout-HomePage.cshtml", the alternate shape will only be applied to "~/" not "~/home-es-MX". If we check the "Set as home page" option on one of the other translations, it becomes "~/" and then will use "Layout-HomePage.cshtml".

Is this expected behavior or a bug? I do not see any logic in v1.3 that would attribute multiple translations to the same homepage layout. The value is just stored in Settings_SiteSettingsPartRecord as "RoutableHomePageProvider;<homepage ContentItemRecord_id>"



Oct 21, 2011 at 11:41 PM

the "Homepage" alternate is just a convention instead of "url-", because it would be ugly. What you need is "Layout-url-es-MX" for instance, in addition to "Layout-Homepage"

Oct 26, 2011 at 11:06 PM
Edited Oct 26, 2011 at 11:07 PM

Thank you. This is works for me.

In my case, the layout stays fundamentally the same between translations so copying my homepage layout for each translation seemed redundant. However, I know that alternating per language may also be desired.

Would it make sense to implicitly use whatever alternate is used by the default language unless a language specific alternate exists? In effect, "Layout-url-home" or "Layout-Homepage" would become the more appropriate choice for "~/home-es-MX" over the base "Layout".

Of course, I realize that if the desire was to alternate only the default language of a page explicitly (current behavior), it would then be necessary to alternate every other translation to behave as "Layout" again resulting in the same pattern.

This could very well just be a quagmire of my own invention so feel free to ignore if the idea lacks merit :)

Oct 26, 2011 at 11:29 PM

url is really for the url, so there can't be a fallback to url-home.

But yes, the real point here would be to make Localization alternates. It's very easy actually, take the code from the UrlAlternates provider, and replace using the ICultureSelector.

Oct 27, 2011 at 2:02 PM

Perfect. Thank you for the guidance.