I ran into an issue with how this package interacts with a solution that's already localised.
During registration of the Storyblok middleware this section was interfering with our localisation configuration causing existing sections of the application to not behave as intended.
I've made a few changes to the library so that it is able to integrate with a solution that's already been localised - here's the commit: myquay@2ab0f64
Let me know if this is something you think could help other users of your library and I'm happy to submit a PR otherwise feel free to close the issue.
requestLocalizationOptions.Value.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
{
// special handling of Storyblok preview URLs that contain the language, like ~/de/home vs. ~/home
// if we have such a URL, we also change the current culture accordingly
var slug = context.Request.Path.ToString().Trim('/');
var supportedCultures = requestLocalizationOptions?.Value?.SupportedCultures?.Select(s => s.Name).ToArray() ?? Array.Empty<string>();
foreach (var supportedCulture in supportedCultures)
{
if (slug.StartsWith($"{supportedCulture}/", StringComparison.OrdinalIgnoreCase) || slug.Equals(supportedCulture, StringComparison.OrdinalIgnoreCase))
return await Task.FromResult(new ProviderCultureResult(supportedCulture));
}
return await Task.FromResult<ProviderCultureResult?>(null);
}));
var configuredCultures = requestLocalizationOptions?.SupportedCultures?.Select(s => s.Name) ?? new string[] { };
if(Settings.SupportedCultures.Any(x => !configuredCultures.Any(y => y.Equals(x, StringComparison.OrdinalIgnoreCase))))
{
throw new Exception("All supported cultures in Storyblok must be configured in ASP.NET.");
}