From e7c9a1b79f973d29e0bf5e0b9452ae9c0753c6e0 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 27 Dec 2019 15:57:12 -0500 Subject: [PATCH] Fix issue where wrong directory separator slash could end up in language translation files --- .../LanguageSupport/LanguageTranslator.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/wire/modules/LanguageSupport/LanguageTranslator.php b/wire/modules/LanguageSupport/LanguageTranslator.php index 7436d1fc..13f8a88f 100644 --- a/wire/modules/LanguageSupport/LanguageTranslator.php +++ b/wire/modules/LanguageSupport/LanguageTranslator.php @@ -138,11 +138,15 @@ class LanguageTranslator extends Wire { foreach($translations as $hash => $translation) { if(!strlen($translation['text'])) unset($translations[$hash]); } + if(strpos($file, "\\") !== false && strpos($file, "\\" . basename($file))) { + // file has MS-DOS style slashes and they are not escapes, convert to unix + $file = str_replace("\\", '/', $file); + } return array( 'file' => $file, 'textdomain' => $textdomain, 'translations' => $translations - ); + ); } /** @@ -257,9 +261,13 @@ class LanguageTranslator extends Wire { */ protected function textdomainString($textdomain) { - if(is_string($textdomain) && (strpos($textdomain, DIRECTORY_SEPARATOR) !== false || strpos($textdomain, '/') !== false)) $textdomain = $this->filenameToTextdomain($textdomain); // @werker #424 - else if(is_object($textdomain)) $textdomain = $this->objectToTextdomain($textdomain); - else $textdomain = strtolower($textdomain); + if(is_string($textdomain) && (strpos($textdomain, DIRECTORY_SEPARATOR) !== false || strpos($textdomain, '/') !== false)) { + $textdomain = $this->filenameToTextdomain($textdomain); // @werker #424 + } else if(is_object($textdomain)) { + $textdomain = $this->objectToTextdomain($textdomain); + } else { + $textdomain = strtolower($textdomain); + } // just in case there is an extension on it, remove it if(strpos($textdomain, '.')) $textdomain = basename($textdomain, '.json');