@@ -43,19 +43,20 @@ function interledger_preprocess_html(&$variables) {
4343 * See the menu--main.html.twig template for the list of variables.
4444 */
4545function 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';
46+ $default_lang_code = strtolower(\Drupal::languageManager()->getDefaultLanguage()->getId());
47+ $lang_code = strtolower(\Drupal::languageManager()->getCurrentLanguage()->getId());
48+ $needs_translation = $lang_code !== $default_lang_code;
5049
51- if ($variables['menu_name'] === 'main') {
50+ if ($variables['menu_name'] === 'main' && $needs_translation) {
51+ $path_to_translate = '/developers';
52+ $translated_path = 'developers/' . $lang_code;
5253 foreach ($variables['items'] as $key => $item) {
5354 if (!empty($item['below']) && is_array($item["below"])) {
5455 foreach ($item['below'] as $skey => $submenu) {
5556 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));
57+ $url_string = strtolower( $submenu['url']->toString() );
58+ if (str_starts_with ($url_string, $path_to_translate)) {
59+ $translationStr = substr_replace($url_string, $translated_path , 0, strlen($path_to_translate));
5960 $translationUrl = Url::fromUri('base:' . $translationStr);
6061 $variables['items'][$key]['below'][$skey]['url'] = $translationUrl;
6162 }
0 commit comments