From 5d7ac91a23d7fb45ab544b73e56f92a3629617b8 Mon Sep 17 00:00:00 2001 From: Harry Werkmeister Date: Tue, 15 Mar 2022 09:01:23 +0100 Subject: [PATCH] fix: Issue barryvdh/laravel-translation-manager#406 This fix makes it possible that folder structures used in translation strings are used as group keys. --- src/Manager.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Manager.php b/src/Manager.php index 26cc0dab..b49a6fe4 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -166,16 +166,16 @@ public function findTranslations($path = null) $functions = $this->config['trans_functions']; $groupPattern = // See https://regex101.com/r/WEJqdL/6 - "[^\w|>]". // Must not have an alphanum or _ or > before real method - '('.implode('|', $functions).')'. // Must start with one of the functions - "\(". // Match opening parenthesis - "[\'\"]". // Match " or ' - '('. // Start a new group to match: - '[a-zA-Z0-9_-]+'. // Must start with group - "([.](?! )[^\1)]+)+". // Be followed by one or more items/keys - ')'. // Close group - "[\'\"]". // Closing quote - "[\),]"; // Close parentheses or new parameter + "[^\w|>]" . // Must not have an alphanum or _ or > before real method + '(' . implode('|', $functions) . ')' . // Must start with one of the functions + "\(" . // Match opening parenthesis + "[\'\"]" . // Match " or ' + '(' . // Start a new group to match: + '[\/a-zA-Z0-9_-]+' . // Must start with group + "([.](?! )[^\1)]+)+" . // Be followed by one or more items/keys + ')' . // Close group + "[\'\"]" . // Closing quote + "[\),]"; // Close parentheses or new parameter $stringPattern = "[^\w]". // Must not have an alphanum before real method @@ -202,7 +202,7 @@ public function findTranslations($path = null) if (preg_match_all("/$stringPattern/siU", $file->getContents(), $matches)) { foreach ($matches['string'] as $key) { - if (preg_match("/(^[a-zA-Z0-9_-]+([.][^\1)\ ]+)+$)/siU", $key, $groupMatches)) { + if (preg_match("/(^[\/a-zA-Z0-9_-]+([.][^\1)\ ]+)+$)/siU", $key, $groupMatches)) { // group{.group}.key format, already in $groupKeys but also matched here // do nothing, it has to be treated as a group continue;