Try the following solution:
We need to override Sitecore.Pipelines.PreprocessRequest.StripLanguage
using Sitecore.Diagnostics;
using Sitecore.Globalization;
using Sitecore.Web;
using System.Web;
using Sitecore;
using Sitecore.Pipelines.PreprocessRequest;
namespace YourProject
{
public class StripLanguage : Sitecore.Pipelines.PreprocessRequest.StripLanguage
{
/// <summary>Processes the specified arguments.</summary>
/// <param name="args">The arguments.</param>
public override void Process(PreprocessRequestArgs args)
{
Assert.ArgumentNotNull((object)args, "args");
Language language = StripLanguage.ExtractLanguage(args.Context.Request);
if (language == (Language) null)
{
//if url doesn't contain language name, we will set the default language
language = Sitecore.Globalization.Language.Parse("en");
}
Context.Language = language;
Context.Data.FilePathLanguage = language;
}
/// <summary>
/// Extracts the language from the file path of the current request.
/// </summary>
/// <param name="request">The HTTP request.</param>
/// <returns>The language.</returns>
private static Language ExtractLanguage(HttpRequest request)
{
Assert.ArgumentNotNull((object)request, "request");
string languageName = WebUtil.ExtractLanguageName(request.FilePath);
if (string.IsNullOrEmpty(languageName))
return (Language)null;
Language result;
if (!Language.TryParse(languageName, out result))
return (Language)null;
return result;
}
}
}
Then you need to replace the Sitecore's StripLanguage with your implementation. Add the following CustomStripLanguageProcessor.config file into the include folder:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<!--Pipelines-->
<pipelines>
<preprocessRequest>
<processor type="Sitecore.Pipelines.PreprocessRequest.StripLanguage, Sitecore.Kernel" >
<patch:delete/>
</processor>
<processor type="YourProject.StripLanguage, YourProject" />
</preprocessRequest>
</pipelines>
</sitecore>
</configuration>
Now, when your url have the /sv-se/ , the Swedish language will be set as a context language. But if it is not, the default language will be used.