8

Sitecore appears to be doing something freaky with the language variable in it's Context object. If I load a CMS page using the url ?sc_Lang=ru-RU (get the Russian version of my site), by the time it get's to my MVC controller it's reset to the language back to en

public PartialViewResult Navigation()
{
    //en
    var language = Sitecore.Context.Language;
}

I know that sitecore does set this at some point because if I add a HTTP pipeline I can see Sitecore.Context.Language as ru-RU:

public class LanguageResolver
{
    public void Process(Sitecore.Pipelines.HttpRequest.HttpRequestArgs args)
    {
        //ru-RU
        var language = Sitecore.Context.Language;
    }
}

Registered:

<processor type="Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel"/>
<processor type="namespace.LanguageResolver,RR.Web.Sc.Extensions" patch:source="Languages.config"/>

as recommended on the sitecore blog post

I did some digging into the sitecore dlls and I noticed that Sitcore.Context.Language is basically a wrapper for HttpContext.Current.Items["sc_Language"]. When I inspect this I see the same results (i.e. in the pipeline it's ru-RU in the controller it's en)

So something somewhere is turning this HttpContext Item to "en".

As an experiment I dropped a new variable into the Items collection. I can then see this again (in it's correct state) in Controller, so the Items collection is getting passed into the controller correctly.

I didn't originally develop this site but I can't see anywhere in the code base that changes this language variable.

Has anyone else experienced this? Anything I've missed? Anything I need to configure, check?

The sitecore docs (as usual) are pretty woeful on this subject.


To follow up on the comment from @jammykam:

I can see the lang cookie the Response Set-Cookie: redrow#lang=ru-RU; path=/ and the languages are set up:

enter image description here

enter image description here

Liam
  • 27,717
  • 28
  • 128
  • 190
  • Just to be sure something funky is not happening, can you try clearing your cookies (or check them and make sure `website#lang=ru-RU`). Have you added `ru-RU` to Sitecore? Does your local system support it? – jammykam Nov 04 '15 at 12:39
  • @jammykam, added details above. I'm intrigued if anyone has view'd this in an MVC environment before? I'm guessing it's worked for someone, somewhere? – Liam Nov 04 '15 at 13:52
  • Can you move your language resolver before item resolver? Default order in Sitecore is: other procesors ... and after – Vlad Iobagiu Nov 04 '15 at 13:56
  • The language resolver isn't actually doing anything at the moment though, I'm just using it as an intercept to see what the language is set to further up the pipeline. @sitecoreclimber Now that said it might be interesting to move it around in the pipeline...mmm – Liam Nov 04 '15 at 13:58
  • Just check if is working and if yes I will move my comment like an answer – Vlad Iobagiu Nov 04 '15 at 14:02
  • Moving the pipeline around hasn't really helped. As far as I can tell the language is correct in all the httpRequestBegin pipelines. I even overrode a few to make sure that the standard one's weren't changing this. – Liam Nov 04 '15 at 15:03
  • And just to be sure, the language that has been installed is `ru-RU` and not just `ru`? Did you add the language via the Sitecore Control Panel? – jammykam Nov 04 '15 at 15:57
  • yes and yes @jammykam – Liam Nov 05 '15 at 09:13
  • I've given up, I'm implementing my own and storing it in the context items myself. I wanted a non-standard location for the language anyway. – Liam Nov 05 '15 at 09:13
  • You can open User Manager and set up languages that you prefer per users. It will work for Content Editor. However in you controller language is get from site context. Go to your site configuration and set language that you need . – Anton May 13 '16 at 13:11
  • Are you logged with a sitecore user at the same time ? – Laurent Lequenne Aug 31 '16 at 23:02

1 Answers1

0

There are a few places in code where Language setter is used OOB in Sitecore 10:

enter image description here

Even though callees from Sitecore.MVC namespace on top of suspected list, I'd recommend to debug Sitecore.Context.Language setter by restoring PDBs and loading them to debugger to get the actual culprit. You'll also see the mechanics/motivation behind the language-switch logic.

Even though getter might be optimized, you still could disable optimizations to ease debugging.

Nikolay Mitikov
  • 523
  • 2
  • 16
  • I haven't worked on sitecore for about 6 years so I can't really upvote or accept this answer as I don't know if it's helpful or not. So I'll have to see what other people think – Liam Feb 15 '21 at 08:58