Skip to content

Commit ec6da1c

Browse files
committed
chore: Handle translation of /developers links in main menu for Spanish
1 parent a9f457f commit ec6da1c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

web/themes/interledger/interledger.theme

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use \Drupal\Core\Url;
4+
35
/**
46
* Implements hook_preprocess()
57
*
@@ -32,3 +34,34 @@ function interledger_preprocess_html(&$variables) {
3234
$variables['attributes']['class'][] = 'page-' . $statusCode;
3335
}
3436
}
37+
38+
/**
39+
* Prepares variables for the menu--main template.
40+
*
41+
* Default template: menu--main.html.twig.
42+
*
43+
* See the menu--main.html.twig template for the list of variables.
44+
*/
45+
function interledger_preprocess_menu__main(&$variables) {
46+
$language_interface = \Drupal::languageManager()->getCurrentLanguage()->getName();
47+
$needs_translation = strtolower($language_interface) === 'es';
48+
$path_to_translate = '/developers';
49+
$translation_path = 'developers/es';
50+
51+
if ($variables['menu_name'] === 'main') {
52+
foreach ($variables['items'] as $key => $item) {
53+
if (!empty($item['below']) && is_array($item["below"])) {
54+
foreach ($item['below'] as $skey => $submenu) {
55+
if (isset($submenu['url']) && is_object($submenu['url'])) {
56+
$url_string = $submenu['url']->toString();
57+
if (str_contains($url_string, $path_to_translate) && $needs_translation) {
58+
$translationStr = substr_replace($url_string, $translation_path, 0, strlen($path_to_translate));
59+
$translationUrl = Url::fromUri('base:' . $translationStr);
60+
$variables['items'][$key]['below'][$skey]['url'] = $translationUrl;
61+
}
62+
}
63+
}
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)