Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application language support #8483

Closed

Conversation

ZuperNova
Copy link

@ZuperNova ZuperNova commented May 6, 2022

Application language support

Added support for changing the language in the application.

Description

This pull request contains an implementation that makes it possible to fetch the supported languages in an application.

Altinn-studio

Added a new model for application language.

Thoughts:
The TextResources-model is using the same attribute as the new model ApplicationLanguage. The attribute language should be renamed to languageCode so that it is a more descriptive name. This also enables the oppertunity to rename the attribute languageDescription to language in ApplicationLanguage. Doing this requires renaming throughout the project.

app-frontend-react

Expanded the NavBar.tsx to contain the DropdownComponent.

The dropdown used in this pull request is a the same component used within the application (DropdownComponent). This component is made reusable.

The attribute showLanguageDropdown in settings.json is used to determin if the dropdown menu should be visible or not.

The chosen language is stored in the local storage.

The urlAppHelper contains the new exposed enpoint for fetching the supported languages for an application.

There has been created a new saga for application language.

Both of the sagas for options and textResouce has gotten some changes so that it uses the language from the dropdown.

Tests have been added and updated.

app-template-dotnet

A new controller is added specifically for the application language. There is now one endpoint that exposes the supported languages of the specific application. The functionality behind this is introduced in the AppResorucesSI. Here it has been added a new function that traversers through every file in the text resource directory. While traversing it is looking for three attributes in the resource file, "language", "languageDescription" and "dropdownLabel". These are mapped over to the new model created in the Altinn-Studio Repo, ApplicationLanguage and added to the list. The function returns a list of ApplicationLanguages when done executing. There is also added validation that when fails returns an empty list.

Example:

resource.nb.json

{
    "language": "nb",
    "languageDescription": "Norsk bokmål",
    "dropdownLabel": "Språk",
    "resources": [...]
    ...
}

resource.en.json

{
    "language": "en",
    "languageDescription": "English",
    "dropdownLabel": "Language",
    "resources": [...]
    ...
}

The function will then return:

new List<ApplicationLanguage>() {
    new ApplicationLanguage() {
        Language = "nb",
        LanguageDescription = "Norsk bokmål",
        DropdownLabel = "Språk"
    },
    new ApplicationLanguage() {
        Language = "en",
        LanguageDescription = "English",
        DropdownLabel = "Language"
    }
}

Altinn-cdn

Added schema-description for showLanguageDropdown and also added the missing schema-description for hideCloseButton.

Altinn-studio-docs

Added documentation for the application translator.

Known bugs/missing elements

Error handling is not present at the moment in the frontend.

When refreshing the page the dropdown dissapears.

The PR is created even though we are awear of the issues mentioned above to give you a look and to comment on it.

Linked PRs

Altinn-studio-docs: Altinn/altinn-studio-docs#516

app-frontend-react: Altinn/app-frontend-react#83

Altinn-cdn: Altinn/altinn-cdn#96

app-template-dotnet: Altinn/app-template-dotnet#85

Fixes

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)
  • Changelog is updated with a separate linked PR

@RonnyB71
Copy link
Member

Thx:) We'll process this PR, and related PR's, as soon as possible.

@tjololo
Copy link
Member

tjololo commented May 11, 2022

Once again, thank you so much for contributing an entire epic!
To ease the usage, keep the feel consistent and reduce the chances of later breaking changes we have som thoughts about the architecture for this component

  1. Change the schema-description from showLanguageDropdown to showLanguageSelector. Just in case we don’t use a dropdown in the future
  2. Remove languageDescription and dropdownLabel from resources.xx.json and ApplicationLanguage.cs. We would like to serve the defaults for these fields from the template, you find the relevant default served texts here . The app developer should be able to override these defaults with text resources. This can be accomplished by using the getTextFromAppOrDefault util. Suggested keys: language.full_name and language.selector.label

We will as soon as possible get back to you with more local review on the related pull requests.
If you need some more information please dont hesitate to reach out here or on slack, we will be more than happy to see this pull request safely into main :)

@ZuperNova ZuperNova force-pushed the application-language-support branch from 1e0ce33 to d9e7dd9 Compare May 23, 2022 08:13
@github-actions github-actions bot added area/authentication Area: Issues related to authentication in Altinn Studio area/authorization Area: Issues related to roles and rights on apps, such as who can instantiate, sign etc. area/dashboard Area: Related to the dashboard application area/events area/ui-editor Area: Related to the designer tool for assembling app UI in Altinn Studio. solution/apps Issues related to apps or the Altinn Apps infrastructures. solution/studio/designer Issues related to the Altinn Studio Designer solution. solution/studio/repos Issues related to the Altinn Studio Repos solution (Gitea). labels May 23, 2022
@ZuperNova ZuperNova force-pushed the application-language-support branch from d9e7dd9 to 260b4b7 Compare May 23, 2022 08:35
@RonnyB71
Copy link
Member

@ZuperNova I've started some preliminary testing of this feature. What I've done so far is:

  1. Created a test application with one dropdown component and the navigation bar componet
  2. Running the test application locally using the latest backend including the code merged into 5.2.0-alpha.1 and serving the frontend based on your branch
  3. Updated settings.json to include "showLanguageSelector": true

Anything else I need to do to get this up and running? Currently I don't see the language selector, nor do I see any language requests from the frontend so I've probably missed something.

@ZuperNova
Copy link
Author

@ZuperNova I've started some preliminary testing of this feature. What I've done so far is:

  1. Created a test application with one dropdown component and the navigation bar componet
  2. Running the test application locally using the latest backend including the code merged into 5.2.0-alpha.1 and serving the frontend based on your branch
  3. Updated settings.json to include "showLanguageSelector": true

Anything else I need to do to get this up and running? Currently I don't see the language selector, nor do I see any language requests from the frontend so I've probably missed something.

You also need to include some text resources (nb.json, en.json). Without this the frontend won't render the selector.

@RonnyB71
Copy link
Member

You also need to include some text resources (nb.json, en.json). Without this the frontend won't render the selector.

Sorry, forgot to mention that but I created text resources in the above setup already. So I have resource.en.json, resource.nb.json and resource.nn.json - all with appName and one additional label translated.

I see that your service work as expected because I created a dynamic options passing in the IApplicationLanguage interface and used that to create options for a dropdown list. Which is then populated with en, nb and nn.

@ZuperNova
Copy link
Author

ZuperNova commented May 30, 2022

You also need to include some text resources (nb.json, en.json). Without this the frontend won't render the selector.

Sorry, forgot to mention that but I created text resources in the above setup already. So I have resource.en.json, resource.nb.json and resource.nn.json - all with appName and one additional label translated.

I see that your service work as expected because I created a dynamic options passing in the IApplicationLanguage interface and used that to create options for a dropdown list. Which is then populated with en, nb and nn.

Okay, I understand. Have you also included the different attributes in the text resources that the selector use?

resource.nb.json

{
    "id": "language.selector.label",
    "value": "Språk"
},
{
    "id": "language.full_name.nb",
    "value": "Norsk bokmål"
},
{
    "id": "language.full_name.en",
    "value": "Engelsk"
}

resource.en.json

{
    "id": "language.selector.label",
    "value": "Language"
},
{
    "id": "language.full_name.en",
    "value": "English"
},
{
    "id": "language.full_name.nb",
    "value": "Norwegian bokmål"
}

@RonnyB71
Copy link
Member

RonnyB71 commented Jun 2, 2022

Okay, I understand. Have you also included the different attributes in the text resources that the selector use?
Nope, I missed that one. Added it now, but still no language selector showing up.

I'm suspecting that it's not triggering as I see no requests from the frontend to the new api. My settings.json looks like this:

{
  "$schema": "https://altinncdn.no/schemas/json/layout/layoutSettings.schema.v1.json",
  "pages": {
    "order": [
      "FormLayout",
      "Side2"
    ]
  },
  "showLanguageSelector": true
}

Anything else I've missed?

@ZuperNova
Copy link
Author

Okay, I understand. Have you also included the different attributes in the text resources that the selector use?
Nope, I missed that one. Added it now, but still no language selector showing up.

I'm suspecting that it's not triggering as I see no requests from the frontend to the new api. My settings.json looks like this:

{
  "$schema": "https://altinncdn.no/schemas/json/layout/layoutSettings.schema.v1.json",
  "pages": {
    "order": [
      "FormLayout",
      "Side2"
    ]
  },
  "showLanguageSelector": true
}

Anything else I've missed?

The showLanguageSelector needs to be inside of pages

{
  "$schema": "https://altinncdn.no/schemas/json/layout/layoutSettings.schema.v1.json",
  "pages": {
    "order": [
      "FormLayout",
      "Side2"
    ],
    "showLanguageSelector": true
  }
}

@RonnyB71
Copy link
Member

RonnyB71 commented Jun 2, 2022

The showLanguageSelector needs to be inside of pages

Sigh, seem like I need to brush up my reading skills. Thx for your patience:) Up and running now.

@ZuperNova
Copy link
Author

Sigh, seem like I need to brush up my reading skills. Thx for your patience:) Up and running now.

Hehe, no worries! Glad it worked out 😄

@RonnyB71 RonnyB71 closed this Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/authentication Area: Issues related to authentication in Altinn Studio area/authorization Area: Issues related to roles and rights on apps, such as who can instantiate, sign etc. area/dashboard Area: Related to the dashboard application area/ui-editor Area: Related to the designer tool for assembling app UI in Altinn Studio. external-contribution-❤️ Pull request from a developer outside the Altinn teams. solution/apps Issues related to apps or the Altinn Apps infrastructures. solution/platform Issues related to Altinn Platform solutions. solution/studio/designer Issues related to the Altinn Studio Designer solution. solution/studio/repos Issues related to the Altinn Studio Repos solution (Gitea).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants