diff --git a/includes/lib/transifex-live-integration-picker.php b/includes/lib/transifex-live-integration-picker.php index 84ea996..158e570 100644 --- a/includes/lib/transifex-live-integration-picker.php +++ b/includes/lib/transifex-live-integration-picker.php @@ -77,17 +77,20 @@ function render() { // in this case return the url_path with e.g engagement => /engagement // Otherwise remove the part from url string until the language prefix // e.g el/sample_page =>sample_page - // Check if URL corresponds to an image. If so, leave it unmodified. - if ($this->is_image_url($url_path)) { - $source_url_path = $url_path; + if (strpos($url_path, $lang ) !== false && $url_path !== $lang && strpos($url_path, $lang .'/' ) === false) { + $source_url_path = '/' . ltrim( $url_path, '/' ); } else { - if (strpos($url_path, $lang ) !== false && $url_path !== $lang && strpos($url_path, $lang .'/' ) === false) { - $source_url_path = '/' . ltrim( $url_path, '/' ); - } else { - $source_url_path = (substr($url_path, 0, strlen($lang)) === $lang) ? substr($url_path, strlen($lang)) : $url_path; - } + $source_url_path = (substr($url_path, 0, strlen($lang)) === $lang) ? substr($url_path, strlen($lang)) : $url_path; } $url_map = Transifex_Live_Integration_Common::generate_language_url_map( $source_url_path, $this->tokenized_url, $this->language_map ); + + // Ensure image URLs are not modified by the language prefix + foreach ($url_map as $key => $url) { + if (strpos($url, '/wp-content/uploads/') !== false) { + continue; + } + $url_map[$key] = rtrim($url, '/') . '/'; + } $site_url_slash_maybe = (new Transifex_Live_Integration_WP_Services())->get_site_url($this->is_subdirectory_install); $site_url = rtrim( $site_url_slash_maybe, '/' ) . '/'; $source_url_path = ltrim( $source_url_path, '/' );