|
8 | 8 | * License: GNU/GPLv2
|
9 | 9 | * @see LICENSE.txt
|
10 | 10 | *
|
11 |
| - * This file: The loader (last modified: 2023.04.01). |
| 11 | + * This file: The loader (last modified: 2023.04.03). |
12 | 12 | */
|
13 | 13 |
|
14 | 14 | namespace phpMussel\Core;
|
@@ -760,17 +760,25 @@ public function timeFormat(int $Time, $In)
|
760 | 760 |
|
761 | 761 | /**
|
762 | 762 | * Replaces encapsulated substrings within a string using the values of the
|
763 |
| - * corresponding elements within the supplied array. |
| 763 | + * corresponding elements within an array. |
764 | 764 | *
|
765 | 765 | * @param array $Needles An array containing replacement values.
|
766 | 766 | * @param string $Haystack The string to work with.
|
| 767 | + * @param bool $L10N Whether to parse L10N placeholders found in the haystack. |
767 | 768 | * @return string The string with its encapsulated substrings replaced.
|
768 | 769 | */
|
769 |
| - public function parse(array $Needles, string $Haystack): string |
| 770 | + public function parse(array $Needles, string $Haystack = '', bool $L10N = false): string |
770 | 771 | {
|
771 |
| - if (empty($Haystack)) { |
| 772 | + if ($Haystack === '') { |
772 | 773 | return '';
|
773 | 774 | }
|
| 775 | + if ($L10N && preg_match_all('~\{([A-Za-z\d_ -]+)\}~', $Haystack, $Matches)) { |
| 776 | + foreach ($Matches[1] as $Key) { |
| 777 | + if (($Value = $this->L10N->getString($Key)) !== '') { |
| 778 | + $Haystack = str_replace('{' . $Key . '}', $Value, $Haystack); |
| 779 | + } |
| 780 | + } |
| 781 | + } |
774 | 782 | foreach ($Needles as $Key => $Value) {
|
775 | 783 | if (!is_array($Value) && $Value !== null) {
|
776 | 784 | $Haystack = str_replace('{' . $Key . '}', $Value, $Haystack);
|
|
0 commit comments