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

UHF-8088: Add language attributes to header top and branding regions. #646

Merged
merged 5 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -296,6 +295,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;

Expand Down Expand Up @@ -1437,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'];
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions templates/block/block--external-menu-block-fallback.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
15 changes: 14 additions & 1 deletion templates/content/node--announcement--default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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] %}

<section aria-label="{{ type_label }}" class="announcement js-announcement {{ block_modifier }} container" data-uuid="{{ node.uuid.value }}">
<div class="announcement__container">
<div {{ create_attribute(announcement_attributes) }}>
<div class="announcement__content">
{% if content.body|render != null %}
<span class="announcenemnt__content-body">
Expand Down
14 changes: 13 additions & 1 deletion templates/layout/page.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@
{% endif %}

{% if page.header_branding %}
<div id="header-branding" class="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 %}
<div {{ create_attribute(header_branding_attributes) }}>
{% set prefix = active_theme == 'hdbt_subtheme' ? 'hdbt_subtheme_' : '' %}

{# Manually select which blocks to render in header branding region. #}
Expand Down
2 changes: 1 addition & 1 deletion templates/layout/region--header-top.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
#}
{% if content %}
<div class="header-top">
<div{{ attributes.addClass(region|clean_class) }}>
{{ content }}
</div>
{% endif %}
8 changes: 8 additions & 0 deletions translations/fi.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions translations/sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down