From c2a874001e20cd323e477cb2d2de381890dceb84 Mon Sep 17 00:00:00 2001 From: Juho Lehmonen Date: Fri, 28 Apr 2023 10:30:49 +0300 Subject: [PATCH 1/4] UHF-8088: Add language attributes to header top and branding regions. --- templates/layout/page.html.twig | 14 +++++++++++++- templates/layout/region--header-top.html.twig | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/templates/layout/page.html.twig b/templates/layout/page.html.twig index 6e6e1299a..2a102dbc0 100644 --- a/templates/layout/page.html.twig +++ b/templates/layout/page.html.twig @@ -66,7 +66,19 @@ {% endif %} {% if page.header_branding %} -
+ {% set header_branding_attributes = { + 'id': 'header-branding', + 'class': ['header-branding'] + } + %} + {% if alternative_language %} + {% set header_branding_attributes = header_branding_attributes|merge({ + 'dir': lang_attributes.fallback_dir, + 'lang': lang_attributes.fallback_lang + }) + %} + {% endif %} +
{% set prefix = active_theme == 'hdbt_subtheme' ? 'hdbt_subtheme_' : '' %} {# Manually select which blocks to render in header branding region. #} diff --git a/templates/layout/region--header-top.html.twig b/templates/layout/region--header-top.html.twig index e54c6beca..393d2b2b0 100644 --- a/templates/layout/region--header-top.html.twig +++ b/templates/layout/region--header-top.html.twig @@ -13,7 +13,7 @@ */ #} {% if content %} -
+ {{ content }}
{% endif %} From 7a75e0c7a65efed31790565f0cb9ce1289e74f7c Mon Sep 17 00:00:00 2001 From: Juho Lehmonen Date: Fri, 28 Apr 2023 13:52:50 +0300 Subject: [PATCH 2/4] UHF-8088: Handle announcement fallback language attributes. --- hdbt.theme | 3 +++ .../node--announcement--default.html.twig | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hdbt.theme b/hdbt.theme index 81bcf0c32..62f856813 100644 --- a/hdbt.theme +++ b/hdbt.theme @@ -296,6 +296,9 @@ function hdbt_preprocess_node(&$variables): void { /** @var \Drupal\node\NodeInterface $node */ $node = $variables['node']; + // Add current langcode for easy access. + $variables['node_langcode'] = $node->get('langcode')->value; + // Add current node Url to variable. $variables['node_url'] = !$node->isNew() ? $node->toUrl('canonical') : NULL; diff --git a/templates/content/node--announcement--default.html.twig b/templates/content/node--announcement--default.html.twig index 66d3e9ee8..583647229 100644 --- a/templates/content/node--announcement--default.html.twig +++ b/templates/content/node--announcement--default.html.twig @@ -6,10 +6,23 @@ {% set block_modifier = 'announcement--notification' %} {% endif %} +{% set announcement_attributes = { + 'class': [ + 'announcement__container', + ] +} %} +{% if current_langcode != node_langcode %} + {% set announcement_attributes = announcement_attributes|merge({ + 'dir': lang_attributes.fallback_dir, + 'lang': lang_attributes.fallback_lang + }) + %} +{% endif %} + {% set link = content.field_announcement_link[0] %}
-
+
{% if content.body|render != null %} @@ -26,4 +39,4 @@
-
\ No newline at end of file + From c97fa1f58688a583c926ba9cfdbeb3eeda8aac5a Mon Sep 17 00:00:00 2001 From: Juho Lehmonen Date: Fri, 28 Apr 2023 14:38:31 +0300 Subject: [PATCH 3/4] UHF-8088: Add context to and update translation files for external and mobile menu open and close texts. --- .../block/block--external-menu-block-fallback.html.twig | 4 ++-- translations/fi.po | 8 ++++++++ translations/sv.po | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/templates/block/block--external-menu-block-fallback.html.twig b/templates/block/block--external-menu-block-fallback.html.twig index db1d044f6..0e6edf0f5 100644 --- a/templates/block/block--external-menu-block-fallback.html.twig +++ b/templates/block/block--external-menu-block-fallback.html.twig @@ -55,10 +55,10 @@ anchor_target: '#menu', js_target: 'js-menu-toggle-button', - open_label: 'Menu'|t, + open_label: 'Menu'|t({}, {'context': 'Mobile navigation menu open button text'}), open_screenreader: 'Open navigation menu'|t({}, {'context': 'Mobile navigation menu open button text for screen readers'}), - close_label: 'Close'|t, + close_label: 'Close'|t({}, {'context': 'Mobile navigation menu close button text'}), close_screenreader: 'Close navigation menu'|t({}, {'context': 'Mobile navigation menu close button text for screen readers'}) } %} {% endembed %} diff --git a/translations/fi.po b/translations/fi.po index 4324ccb2a..a6caf24d2 100644 --- a/translations/fi.po +++ b/translations/fi.po @@ -173,6 +173,14 @@ msgstr "Päivitämme sivustoa tällä hetkellä" msgid "You do not have permission to access this page" msgstr "Sinulla ei ole käyttöoikeutta tälle sivulle" +msgctxt "Mobile navigation menu open button text" +msgid "Menu" +msgstr "Valikko" + +msgctxt "Mobile navigation menu close button text" +msgid "Close" +msgstr "Sulje" + msgctxt "Mobile navigation menu open button text for screen readers" msgid "Open navigation menu" msgstr "Avaa navigaatiovalikko" diff --git a/translations/sv.po b/translations/sv.po index 5808ff257..97c32c703 100644 --- a/translations/sv.po +++ b/translations/sv.po @@ -171,6 +171,14 @@ msgstr "" msgid "You do not have permission to access this page" msgstr "Du har inte användarrätt till sidan" +msgctxt "Mobile navigation menu open button text" +msgid "Menu" +msgstr "Meny" + +msgctxt "Mobile navigation menu close button text" +msgid "Close" +msgstr "Stäng" + msgctxt "Mobile navigation menu open button text for screen readers" msgid "Open navigation menu" msgstr "Öppna navigeringsmenyn" From 10f09857ac7ad93cc34b4666970ac2e1b68a0e0b Mon Sep 17 00:00:00 2001 From: Juho Lehmonen Date: Fri, 5 May 2023 11:14:05 +0300 Subject: [PATCH 4/4] UHF-8088: Remove hardcoded primary language values and use defaultLanguageResolver instead. --- hdbt.theme | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/hdbt.theme b/hdbt.theme index 62f856813..635ec33ec 100644 --- a/hdbt.theme +++ b/hdbt.theme @@ -36,16 +36,15 @@ function hdbt_preprocess(&$variables): void { $language = Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT); $variables['current_langcode'] = $language->getId(); $variables['current_language'] = $language->getName(); - $primary_languages = [ - 'fi', - 'en', - 'sv', - ]; - $variables['alternative_language'] = !in_array($variables['current_langcode'], $primary_languages); + + /** @var \Drupal\helfi_api_base\Language\DefaultLanguageResolver $defaultLanguageResolver */ + $defaultLanguageResolver = Drupal::service('helfi_api_base.default_language_resolver'); + $variables['alternative_language'] = $defaultLanguageResolver->isAltLanguage($language->getId()); if ($variables['alternative_language']) { - $variables['lang_attributes']['fallback_lang'] = 'en'; - $variables['lang_attributes']['fallback_dir'] = 'ltr'; + $attributes = $defaultLanguageResolver->getFallbackLangAttributes(); + $variables['lang_attributes']['fallback_lang'] = $attributes['lang']; + $variables['lang_attributes']['fallback_dir'] = $attributes['dir']; } // Toggle between global and local navigation in twig templates. @@ -1440,8 +1439,11 @@ function hdbt_preprocess_social_media_links(&$variables): void { // Add lang and dir attributes if the link text is not translated. if ($key === 'email' && $variables['alternative_language']) { if (!isset(\Drupal::languageManager()->getLanguageConfigOverride($variables['current_langcode'], 'social_media.settings')->get('social_media')['email']['text'])) { - $element['attr']['lang'] = 'en'; - $element['attr']['dir'] = 'ltr'; + /** @var \Drupal\helfi_api_base\Language\DefaultLanguageResolver $defaultLanguageResolver */ + $defaultLanguageResolver = Drupal::service('helfi_api_base.default_language_resolver'); + $attributes = $defaultLanguageResolver->getFallbackLangAttributes(); + $element['attr']['lang'] = $attributes['lang']; + $element['attr']['dir'] = $attributes['dir']; } } }