diff --git a/_includes/2020/templates/Menu.php b/_includes/2020/templates/Menu.php index c2901835..c6cdf1b6 100644 --- a/_includes/2020/templates/Menu.php +++ b/_includes/2020/templates/Menu.php @@ -34,7 +34,8 @@ public static function render(array $fields): void { } /** - * Modify link of the current URL for a given UI language + * Modify link of the current URL for a given UI language. + * Skip if current URL isn't localized (e.g. _legacy) * @param language - language tag to use * @return string - modified URL */ @@ -45,15 +46,13 @@ private static function change_ui_language($language): string { $path = ''; // Replace language if current language in path is valid BCP-47 - // Note: Validate::validate_bcp47 differs from regex in .htaccess if (!empty($parts['path'])) { $path = explode("/", $parts['path']); - if ($path[1] != null ) { - /* TODO: add validation back && class_exists('\\Keyman\\Site\\com\\keyman\\Validation') && - \Keyman\Site\com\keyman\Validation::validate_bcp47($path[1]) != null*/ + if ($path[1] == Locale::pageLocale()) { $path[1] = $language; - } else { - // original URL didn't have a valid BCP-47 so inert it + } else if (preg_match('/^\/(_legacy)\/.*$/i', $path[1], $matches)) { + // original URL didn't have a valid BCP-47, so insert new langage + // Skip for certain paths like: _legacy array_splice($path, 1, 0, $language); } }