Fallback on default culture page

Topics: Feature requests
May 2, 2011 at 12:46 PM
Edited May 2, 2011 at 12:47 PM

If the default website culture is EN:

When you are on a FR page for example , if you switch the language and the page is translated in the new culture, it work fine each time you change the language.

 

but if you add switch the current language to pt-BR, on a page which is not translated, you will stay on the same page.

 

on my mind, i think the user have to be redirected on the same page with the default culture.

 I've made theses modifications on my website:

 

public bool TryFindLocalizedRoute(ContentItem routableContent, string cultureName, out RoutePart localizedRoute) {
           /* if (!routableContent.Parts.Any(p => p.Is<LocalizationPart>())) {
                localizedRoute = null;
                return false;
            }*/

            var siteCulture = _cultureManager.GetCultureByName(_cultureManager.GetSiteCulture());
            var localizations = _localizationService.GetAvailableLocalizations(routableContent, VersionOptions.Published, siteCulture);
            var localizationPart = localizations.FirstOrDefault(l => l.Culture.Culture == cultureName);

            if (localizationPart == null)
            {
                string strCulture = _cultureManager.GetSiteCulture();
                CultureInfo defaultCulture = new CultureInfo(strCulture);
                localizationPart = localizations.FirstOrDefault(l => l.Culture.Culture == defaultCulture.Name);

                if (localizationPart == null)
                {
                    localizedRoute = null;
                    return false;
                }
            }

            var localizedContentItem = localizationPart.ContentItem;
            localizedRoute = localizedContentItem.Parts.Single(p => p is RoutePart).As<RoutePart>();
            return true;
        }


but i'm not sure it work all the time ^^
Coordinator
May 2, 2011 at 1:56 PM

It will not work at all. Moreover, it may cause some errors.

For your needs you can try something like this:

public bool TryFindLocalizedRoute(ContentItem routableContent, string cultureName, out RoutePart localizedRoute) {
            if (!routableContent.Parts.Any(p => p.Is<LocalizationPart>())) {
                localizedRoute = null;
                return false;
            }

            var siteCulture = _cultureManager.GetCultureByName(_cultureManager.GetSiteCulture());
            var localizations = _localizationService.GetAvailableLocalizations(routableContent, VersionOptions.Published, siteCulture);
            var localizationPart = localizations.FirstOrDefault(l => l.Culture.Culture == cultureName);

            //try get localization part for default site culture
            if (localizationPart == null) {
                localizationPart = localizations.FirstOrDefault(l => l.Culture.Equals(siteCulture));
            }

            if (localizationPart == null) {
                localizedRoute = null;
                return false;
            }

            var localizedContentItem = localizationPart.ContentItem;
            localizedRoute = localizedContentItem.Parts.Single(p => p is RoutePart).As<RoutePart>();
            return true;
        }

Coordinator
May 2, 2011 at 1:58 PM

I will add this to the Issue Tracker and fix in the next release.

Coordinator
May 2, 2011 at 3:24 PM

Implemented in 1.1.3.1