From 3e99e7a52aac89a9ceb15c91269a1f7d9ed03830 Mon Sep 17 00:00:00 2001 From: Medi4tor Date: Wed, 21 Feb 2018 11:18:25 +0100 Subject: [PATCH] NEPT-1804: Use the translated path of a content if exists. (#13) * NEPT-1804: Use the translated path of a content if exists. * NEPT-1804: Add missing param doc in _ec_resp_nexteuropa_multilingual_language_list_column(). * NEPT-1804: $all_paths[$language->language] is set. --- template.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/template.php b/template.php index ba6ae75..e54325c 100644 --- a/template.php +++ b/template.php @@ -1769,8 +1769,8 @@ function ec_resp_nexteuropa_multilingual_language_list(array $variables) { $first_half = array_slice($variables['languages'], 0, $half); $second_half = array_slice($variables['languages'], $half); - $content .= _ec_resp_nexteuropa_multilingual_language_list_column($first_half, $variables['path'], $options); - $content .= _ec_resp_nexteuropa_multilingual_language_list_column($second_half, $variables['path'], $options); + $content .= _ec_resp_nexteuropa_multilingual_language_list_column($first_half, $variables['path'], $options, $variables['all_paths']); + $content .= _ec_resp_nexteuropa_multilingual_language_list_column($second_half, $variables['path'], $options, $variables['all_paths']); $content .= ''; @@ -1786,18 +1786,28 @@ function ec_resp_nexteuropa_multilingual_language_list(array $variables) { * The internal path being linked to. * @param array $options * An associative array of additional options. + * @param array $all_paths + * An associative array of paths keyed by their language code. + * If it is not empty, the array items will be used to generate the links of + * language list. * * @return string * Formatted HTML column displaying the list of provided languages. */ -function _ec_resp_nexteuropa_multilingual_language_list_column($languages, $path, $options) { +function _ec_resp_nexteuropa_multilingual_language_list_column($languages, $path, $options, $all_paths = array()) { $content = '
'; foreach ($languages as $language) { $options['attributes']['lang'] = $language->language; $options['attributes']['hreflang'] = $language->language; $options['attributes']['class'] = 'btn splash-page__btn-language'; $options['language'] = $language; - $content .= l($language->native, $path, $options); + + $translated_path = $path; + if (!empty($all_paths[$language->language])) { + $translated_path = $all_paths[$language->language]; + } + + $content .= l($language->native, $translated_path, $options); } $content .= '
';