Alternative to ContentLanguage.PreferredCulture set? (v12)

Vote:
 

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?

#326237
Jul 30, 2024 8:55
Vote:
 

To set the culture for resources, you can just update the UI cuture: Thread.CurrentThread.CurrentUICulture = new("en").

#326241
Jul 30, 2024 16:58
Vote:
 

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.

#326287
Jul 31, 2024 9:22
Vote:
 

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).

#326288
Jul 31, 2024 9:25
Vote:
 

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.

#326290
Jul 31, 2024 9:38
Stefan Holm Olsen - Jul 31, 2024 9:40
Yeah, that was missing from my post. It was a bit unclear whether OP referred to content or formatting and translations.
Vote:
 

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.

#326302
Jul 31, 2024 11:10
Vote:
 

 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.

#326334
Jul 31, 2024 17:26
Vote:
 

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.. 

#326374
Edited, Aug 01, 2024 7:10
Vote:
 

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.

#326377
Aug 01, 2024 7:19
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.