Skip to content

Commit

Permalink
Merge pull request #952 from danskernesdigitalebibliotek/release/brah…
Browse files Browse the repository at this point in the history
…ma-13

Merge Release/brahma 13 into develop
  • Loading branch information
Adamik10 authored Apr 8, 2024
2 parents 2614056 + 852f7e2 commit 4930387
Show file tree
Hide file tree
Showing 28 changed files with 619 additions and 80 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"type": "package",
"package": {
"name": "danskernesdigitalebibliotek/dpl-react",
"version": "2024.14.0",
"version": "2024.14.1",
"type": "drupal-library",
"dist": {
"url": "https://github.com/danskernesdigitalebibliotek/dpl-react/releases/download/2024.14.0/dist-2024-14-0-f90c7120950eda3808e123006f41fd6f76a1e687.zip",
"url": "https://github.com/danskernesdigitalebibliotek/dpl-react/releases/download/2024.14.1/dist-2024-14-1-d7ef96b5383e75108bffd2d633764338f99892e4.zip",
"type": "zip"
},
"require": {
Expand All @@ -52,9 +52,9 @@
"package": {
"name": "danskernesdigitalebibliotek/dpl-design-system",
"type": "drupal-library",
"version": "2024.14.0",
"version": "2024.14.1",
"dist": {
"url": "https://github.com/danskernesdigitalebibliotek/dpl-design-system/releases/download/2024.14.0/dist-2024-14-0-c34d09ae7fd2867f880dfcfd979fa295b4f9cf68.zip",
"url": "https://github.com/danskernesdigitalebibliotek/dpl-design-system/releases/download/2024.14.1/dist-2024-14-1-34c803afbfbc34806ed0fe3c1d864c65172c24f4.zip",
"type": "zip"
}
}
Expand All @@ -74,8 +74,8 @@
"brick/math": "^0.12.1",
"composer/installers": "1.12.0",
"cweagans/composer-patches": "1.7.3",
"danskernesdigitalebibliotek/dpl-design-system": "2024.14.0",
"danskernesdigitalebibliotek/dpl-react": "2024.14.0",
"danskernesdigitalebibliotek/dpl-design-system": "^2024.14",
"danskernesdigitalebibliotek/dpl-react": "^2024.14",
"danskernesdigitalebibliotek/fbs-client": "*",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"deoliveiralucas/array-keys-case-transform": "^1.1",
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module:
config_translation_po: 0
content_lock: 0
crop: 0
customerror: 0
date_range_formatter: 0
datetime: 0
datetime_range: 0
Expand All @@ -27,6 +26,7 @@ module:
dpl_article: 0
dpl_campaign: 0
dpl_dashboard: 0
dpl_error_pages: 0
dpl_event: 0
dpl_favorites_list: 0
dpl_favorites_list_material_component: 0
Expand Down
13 changes: 0 additions & 13 deletions config/sync/customerror.settings.yml

This file was deleted.

80 changes: 62 additions & 18 deletions cypress/e2e/adgangsplatformen.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ describe("Adgangsplatformen", () => {
"The website encountered an unexpected error. Please try again later."
);
});
// TODO: The test should be re-added when the new user registration is implemented.
it.skip("can register a new user and expose the right tokens for the react apps", () => {

// When a user comes back from authentication with MitID, the user should
// not be able to do anything else other than registering or cancelling.
// Check that the header and footer sections is not vissible.
it("does not show header and footer section for unregistered user", () => {
cy.setupAdgangsplatformenRegisterMappinngs({
authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc",
accessToken: "447131b0a03fe0421204c54e5c21a60-new-user",
Expand All @@ -69,9 +72,14 @@ describe("Adgangsplatformen", () => {

cy.clearCookies();
cy.visit("/");
// Open user menu.
cy.get(".header__menu-profile").click();
// Click create profile.
cy.get(".modal-login__btn-create-profile").click();
cy.get("main#main-content").find("a").click();
cy.get("main#main-content")
.get(".paragraphs__item--user_registration_section__link")
.first()
.click();

cy.request("/dpl-react/user-tokens").then((response) => {
expect(response.status).to.eq(200);
Expand All @@ -80,27 +88,49 @@ describe("Adgangsplatformen", () => {
);
});

cy.get(".header").should("not.exist");
cy.get(".footer").should("not.exist");
});

it("can register a new user and expose the right tokens for the react apps", () => {
cy.setupAdgangsplatformenRegisterMappinngs({
authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc",
accessToken: "447131b0a03fe0421204c54e5c21a60-new-user",
userCPR: 1412749999,
});

cy.clearCookies();
cy.visit("/");
cy.get(".header__menu-profile").click();
cy.get(".modal-login__btn-create-profile").click();
cy.get("main#main-content")
.get(".paragraphs__item--user_registration_section__link")
.first()
.click();
cy.request("/dpl-react/user-tokens").then((response) => {
expect(response.status).to.eq(200);
expect(response.body).contain(
'window.dplReact = window.dplReact || {};\nwindow.dplReact.setToken("unregistered-user", "447131b0a03fe0421204c54e5c21a60-new-user")'
);
});

cy.get('[data-cy="phone-input"]').type("12345678");
cy.get('[data-cy="email-address-input"]').type("[email protected]");
cy.get('[data-cy="pincode-input"]').type("1234");
cy.get('[data-cy="pincode-confirm-input"]').type("1234");
cy.get("#branches-dropdown").select("DK-775100");
cy.get(".btn-primary").click();
cy.get('[data-cy="dashboard-header"]').contains("Your profile");
cy.get('[data-cy="complete-user-registration-button"]').click();
cy.request("/dpl-react/user-tokens").then((response) => {
expect(response.body).contain(
'window.dplReact = window.dplReact || {};\nwindow.dplReact.setToken("user", "447131b0a03fe0421204c54e5c21a60-new-user")'
);
expect(response.body).not.contain(
'window.dplReact = window.dplReact || {};\nwindow.dplReact.setToken("unregistered-user", "447131b0a03fe0421204c54e5c21a60-new-user")'
);
});
});

// When a user comes back from authentication with MitID
// the user should not be able to anything else than registering or logging out.
// So when pressing the user icon after authentication the modal only contains
// the logout button.

// TODO: The test should be re-added when the new user registration is implemented.
it.skip("only shows a logout button in the user menu for an uregistered user", () => {
it("can cancel user registration from the user registration page", () => {
cy.setupAdgangsplatformenRegisterMappinngs({
authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc",
accessToken: "447131b0a03fe0421204c54e5c21a60-new-user",
Expand All @@ -109,15 +139,29 @@ describe("Adgangsplatformen", () => {

cy.clearCookies();
cy.visit("/");
// Open user menu.
cy.get(".header__menu-profile").click();
// Click create profile.
cy.get(".modal-login__btn-create-profile").click();
cy.get("main#main-content").find("a").click();
cy.get("main#main-content")
.get(".paragraphs__item--user_registration_section__link")
.first()
.click();
cy.request("/dpl-react/user-tokens").then((response) => {
expect(response.status).to.eq(200);
expect(response.body).contain(
'window.dplReact = window.dplReact || {};\nwindow.dplReact.setToken("unregistered-user", "447131b0a03fe0421204c54e5c21a60-new-user")'
);
});

cy.get(".header__menu-profile").click();
cy.get(".modal-login").find(".btn-primary").should("have.length", 1);
cy.get(".modal-login").find(".btn-primary").contains("Log out");
cy.get('[data-cy="cancel-user-registration-button"]').click();

cy.request("/dpl-react/user-tokens").then((response) => {
expect(response.body).not.contain(
'window.dplReact = window.dplReact || {};\nwindow.dplReact.setToken("user", "447131b0a03fe0421204c54e5c21a60-new-user")'
);
expect(response.body).not.contain(
'window.dplReact = window.dplReact || {};\nwindow.dplReact.setToken("unregistered-user", "447131b0a03fe0421204c54e5c21a60-new-user")'
);
});
});

beforeEach(() => {
Expand Down
26 changes: 26 additions & 0 deletions cypress/e2e/check-static-pages.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe("Check static pages", () => {
it("does 'Privatlivspolitik' page exist", () => {
cy.visit("/privatlivspolitik");
cy.get("main#main-content").get(".article-header").should("exist");
});
it("does 'Velkommen' page exist", () => {
cy.visit("/velkommen");
cy.get("main#main-content").get(".article-header").should("exist");
});
it("does 'Pausefunktion' page exist", () => {
cy.visit("/pausefunktion");
cy.get("main#main-content").get(".article-header").should("exist");
});
it("does 'Takster' page exist", () => {
cy.visit("/takster");
cy.get("main#main-content").get(".article-header").should("exist");
});
it("does 'Reglement' page exist", () => {
cy.visit("/reglement");
cy.get("main#main-content").get(".article-header").should("exist");
});
it("does 'Opret bruger' page exist", () => {
cy.visit("/opret-bruger");
cy.get("main#main-content").get(".article-header").should("exist");
});
});
78 changes: 78 additions & 0 deletions docs/architecture/adr-011-configuration-translation-system.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Architecture Decision Record: Configuration translation system

## Context

The translation system described in
[adr-009-translation-system](./adr-009-translation-system.md)
handles solely the translations added through Drupals traditional translation handling.

But there was a wish for being able to translate configuration related strings
as well. This includes titles, labels, descriptions,
and other elements in the admin area.

We needed to find a way to handle translation of that kind as well.

## Decision

We went for a solution where we activated the Configuration Translation
Drupal core module and added the [Configuration Translation PO contrib module](https://www.drupal.org/project/config_translation_po).

And we added a range of custom drush commands to handle the various
configuration translation tasks.

## Consequences

By sticking to the handling of PO files in configuration handling that we are
already using in our general translation handling,
we can keep the current Github workflows with some alterations.

Unfortunately handling translations of configuration on local sites
is still as difficult as before.
Translation of configuration texts cannot be found in the standard UI strings
translation list.

### Alterations to former translation workflow

With the config translation PO files added we tried to uncover if POEditor was
able to handle two PO files simultaneously in both import and export context.
It could not.

But we still needed, in Drupal, to be able to import two different files:
One for general translations and one for configuration translations.

We came up with the idea that we could merge the two files going when importing
into POEditor and split it again when exporting from POEditor.

We tried it out and it worked so that was the solution we ended up with.

## Alternatives considered

### Using the config_translate module

We could activate only the config_translate module and add a danish translations
in config/sync.
But then:

1. We would not be able to use POEditor
2. We would need to translate the string on behalf of the administrators

### A hack

We could keep the machine names of the config in English but write the titles,
labels, descriptions in Danish.

But that would have the following bad consequences:

1. The administrators would have to find all the texts in various, not obvious,
places in the admin area.
2. It would differ from the general translation routine which is confusing
3. We would not be able to handle multiple languages for the configuration translations

### Extending the Potion module

Change the Potion module to be able to scan configuration translations as well.

We did not have a clear view of the concept of localizing configuration
translations in the same manner as the Potion module scans the codebase.
It could either be cumbersome to get the two worlds to meet in the same Potion
functionalities or simply incompatible.
42 changes: 34 additions & 8 deletions docs/translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ To make the "translation traffic" work following components are being used:
translatable strings and translations
* [GitHub Actions](.github/workflows/translations.yml)
* Scans codebase for new translatable strings and commits them to GitHub
* Exports translatable configuration strings into a separate `*.config.po` file
* Merges the two files: `*.po` and `*.config.po` into a `*.combined.po` file
* Notifies POEditor that new translatable strings are available
* Publishes `.po` files to GitHub Pages
* When a project is exported from POEditor:
* The `*.combined.po` is split into two files: `*.po` and `*.config.po`
* The `*.po` files are published to GitHub Pages
* POEditor
* Provides an interface for translators
* Links translations with `.po` files on GitHub
Expand All @@ -28,6 +32,9 @@ To make the "translation traffic" work following components are being used:
* Drupal installation which is [configured to use GitHub Pages as an interface
translation server](web/profiles/dpl_cms/dpl_cms.info.yml) from which `.po`
files can be consumed.
* In the development setup and in cronjobs defined in the environments there
are two jobs in charge of importing the regular translations
and the configuration translations.

The following diagram show how these systems interact to support the flow of
from introducing a new translateable string in the codebase to DPL CMS consuming
Expand All @@ -43,15 +50,24 @@ sequenceDiagram
Developer ->> GitHubActions: Merge pull request into develop
GitHubActions ->> GitHubActions: Scan codebase and write strings to .po file
GitHubActions ->> GitHubActions: Fill .po file with existing translations
GitHubActions ->> GitHub: Commit .po file with updated strings
GitHubActions ->> Poeditor: Call webhook
Poeditor ->> GitHub: Fetch updated .po file
Poeditor ->> Poeditor: Synchronize translations with latest strings and translations
Translator ->> Poeditor: Translate strings
Translator ->> Poeditor: Export strings to GitHub
Poeditor ->> GitHub: Commit .po file with updated translations to develop
%% <!-- markdownlint-disable-next-line MD013 -->
Note over GitHubActions,GitHubActions: If config translations<br/>are available<br/>they are used<br/>otherwise empty strings
%% <!-- markdownlint-disable-next-line MD013 -->
GitHubActions ->> GitHubActions: Exports configuration translations into a .config.po file
%% <!-- markdownlint-disable-next-line MD013 -->
GitHubActions ->> GitHubActions: The two .po files are merged together into a .combined.po file
GitHubActions ->> GitHub: Commit combined.po file with updated strings
GitHubActions ->> POEditor: Call webhook
POEditor ->> GitHub: Fetch updated combined.po file
POEditor ->> POEditor: Synchronize translations with latest strings and translations
Translator ->> POEditor: Translate strings
Translator ->> POEditor: Export strings to GitHub
POEditor ->> GitHub: Commit combined.po file with updated translations to develop
GitHub ->> GitHub: .combined.po is split into two files: .po and .config.po
GitHub ->> GitHub: All the po files are published to Github Pages
DplCms ->> GitHub: Fetch .po file with latest translations
DplCms ->> DplCms: Import updated translations
DplCms ->> GitHub: Import config.po file with latest configuration translations
```

## Howtos
Expand All @@ -75,3 +91,13 @@ sequenceDiagram

1. Run `drush locale-check`
2. Run `drush locale-update`

### Import updated config translations

Run `drush dpl_po:import-remote-config-po [LANGUAGE_CODE] [CONFIGURATION_PO_FIL_EXTERNAL_URL]`

Example:

```bash
drush dpl_po:import-remote-config-po da https://danskernesdigitalebibliotek.github.io/dpl-cms/translations/da.config.po
```
Loading

0 comments on commit 4930387

Please sign in to comment.