Altinn / app-lib-dotnet

Libraries used in Altinn Apps
BSD 3-Clause "New" or "Revised" License
8 stars 11 forks source link

Can't get "language" parameter during "IInstantiationProcessor" or "IUserAction" #927

Open violaguttorm opened 1 day ago

violaguttorm commented 1 day ago

Description of the bug

I need the language parameter for these as I need to store certain values in the datamodel in the correct language for the user.

IInstantiationProcessor->DataCreation does not have any parameters for language at all. IUserAction->HandleAction has a parameter of the type UserActionContext, which has a Language-parameter, but this one is always null.

According to the Network-tab in the browser, at least HandleAction does not even send language as part of the HTTP-request, so there in no way I can get it.

Steps To Reproduce

  1. Try instantiating a form and getting the language.
  2. Try to create a button that triggers IUserAction->HandleAction.

Additional Information

No response

ivarne commented 19 hours ago

Correct that it is missing on DataCreation. It's somewhat hard to update interfaces (we need to have an update script for apps, but we only do that on major releases), but we could at least send the data from frontend, so you can get it from _httpContextAccessor.HttpContext.Request.Query.TryGetValue("language", out var language);.

For the UserActionContext, I think the issues should be fixed in the latest versions. What versions of frontend and backend are you using?

ivarne commented 19 hours ago

As far as I read the current main app-frontend-react code, we already send ?language=nb as a query parameter, so getting it from httpContext should work.

violaguttorm commented 16 hours ago

@ivarne I am stuck on front-end version 4.8.2 because of an unrelated issue (https://github.com/Altinn/app-frontend-react/issues/2755), but I can confirm the language parameter is there if I force the newest version. So the instantiation problem is solved as soon as we figure out the other issue! :blush:

The UserActionContext still doesn't work however. It has a parameter for Language (context.Language), but it always becomes null, at least when I test locally. I updated Altinn.App.Api and Altinn.App.Core from version 8.2.4 to version 8.3.8 (what NuGet recommended), but it still didn't work. The "actions" call also does not contain a language query parameter even on the newest (default) front-end. I haven't tried the preview ones.

Am I doing something wrong? Here is the code where I try to print the language code to no avail (excuse the test code around it, I have also taken a look with more sophisticated debugging tools however, and can confirm it is indeed null): https://altinn.studio/repos/brg/rrh-innrapportering/src/branch/560-engelsk-nynorsk/App/logic/Actions/FnrSearchAction.cs#L73

Here is the place I use this for a button in the layout: https://altinn.studio/repos/brg/rrh-innrapportering/src/branch/560-engelsk-nynorsk/App/ui/rrh-form/layouts/rrh_utfylling.json#L183