To set the culture for resources, you can just update the UI cuture: Thread.CurrentThread.CurrentUICulture = new("en").
Hi Martin
If you favor a clean interface approach, use IUpdateContentLanguage.ResolveCulture(string). It will treat your input as priority, and use language rules as fallback if you pass an unsupported culture.
Even simpler would be to add a query string parameter to the API requests: "epsparameter". Then the CMS will handle this for you (using the same failsafe implementation as I mentioned before).
Note that content language does not affect how resources are loaded. If you want to use an interface, then you should use IUpdateUserInterfaceLanguage.ResolveCulture(string culture). A bit weird name, it's actually not resolving, but rather setting it.
Tnaks for all the replies guys. To clarify, we need the translated user friendly name of a category, fetched from a xml translation file in lang folder.
I cant find anything named IUpdateUserInterfaceLanguage or IUpdateContentLanguage. Could it be that it is internal or do i need to upgrade beond EPiServer.CMS.AspNetCore 12.21.1?
I tired setting the Thread.CurrentThread.CurrentUICulture but did not seem to have an effect. I will try this again.
I am qurious about the epsparameter. would i just set it like so /api/myawesomeEndpoint?epsparameter=en
Our work around now is to carry the language as a parameter thruought our code, esentially ignoring the language in context. Not ideal but time is short.
The full name of the interface is EPiServer.Globalization.Internal.IUpdateContentLanguage. I used a similar approach to capture the request language and store it on scheduled Hangfire jobs.
I understand. It is not nice to bring the language forward in parameters again and again, when you can adjust the pipeline from the start.
Your URL sample looks correct. That parameter will be picked up before invoking the controller and action.
The interface is internal in EPiServer.Cms.AspNetCore 12.21.1 so my project cannot use that interface. it is declared like this:
internal interface IUpdateContentLanguage
{
CultureInfo ResolveCulture(string culture);
}
epsparameter=en is not giving me enlish translation for myCategory.LocalizedDescription unfortunately. Maybe its because of our porject setup. i'm going with the workaround for now..
Hi Martin
I should have pointed to EPiServer.Globalization.IUpdateCurrentLanguage.SetRoutedContent() instead (where routedContent can be passed as null in your API controller).
That is not an internal interface. And it will set the content language (for loading the right content version), and the interface and translation languages.
Hi
So we have an mvc.net api that handles some search requests. In this API we use the category api (Category.LocalizedDescription) to retrieve the localized description. This however allways gets the values for the default language.
in v11 you could set ContentLanguage.PreferredCulture and that would tell epi what culture to use when fetching texts, categories or making links. In v12 this is read only though. Any idea what i can use instead to achive similar effect?