From d1d91044f4ef5e063bdab74ff115715ec2490cac Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio@bekerle.com>
Date: Thu, 27 May 2021 13:47:18 +0200
Subject: [PATCH] Add dbp-lang event

---
 packages/app-shell/README.md        | 7 +++++++
 packages/app-shell/src/app-shell.js | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/packages/app-shell/README.md b/packages/app-shell/README.md
index d99df012..17fce0bd 100644
--- a/packages/app-shell/README.md
+++ b/packages/app-shell/README.md
@@ -36,6 +36,13 @@ The component emits `dbp-set-property` events for these attributes:
 - `lang` to propagate a language change (possible values `en`, `de`)
 - `requested-login-status` (possible values `logged-in`, `logged-out`)
 
+### Emitted events
+
+#### dbp-lang
+
+The component emits a `dbp-lang` event when the language is changed (for example in the language picker).
+The `details` attribute of the event is the language (possible values `en`, `de`).
+
 ## Topic Metadata
 
 ```json
diff --git a/packages/app-shell/src/app-shell.js b/packages/app-shell/src/app-shell.js
index 04372c54..4b99658f 100644
--- a/packages/app-shell/src/app-shell.js
+++ b/packages/app-shell/src/app-shell.js
@@ -296,6 +296,14 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
                     this.router.update();
                     this.subtitle = this.activeMetaDataText("short_name");
                     this.description = this.activeMetaDataText("description");
+
+                    // send a dbp-lang event with the language
+                    const event = new CustomEvent('dbp-lang', {
+                        bubbles: true,
+                        composed: true,
+                        detail: this.lang
+                    });
+                    this.dispatchEvent(event);
                 break;
                 case 'metadata':
                 {
-- 
GitLab