Skip to content

Commit

Permalink
fix: Issue #406 (#420)
Browse files Browse the repository at this point in the history
This fix makes it possible that folder structures used in translation strings are used as group keys.

Co-authored-by: Harry Werkmeister <[email protected]>
  • Loading branch information
HarryThe3rd and Harry Werkmeister authored Mar 17, 2022
1 parent 69eef1b commit b21c18a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit b21c18a

Please sign in to comment.