Skip to content

Commit 8814977

Browse files
committed
L10N patch.
1 parent 17f0c8e commit 8814977

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

assets/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ core:
147147
ar: "العربية"
148148
bn: "বাংলা"
149149
de: "Deutsch"
150-
en: "English"
150+
en: "English (AU/GB/NZ)"
151151
en-US: "English (US)"
152152
es: "Español"
153153
fa: "فارسی"
@@ -180,6 +180,7 @@ core:
180180
en-NZ: "en-AU"
181181
en-SG: "en-AU"
182182
en-ZA: "en-AU"
183+
pt-BR: "pt-PT"
183184
zh-HK: "zh-TW"
184185
zh-MO: "zh-TW"
185186
zh-SG: "zh-CN"

src/Loader.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The loader (last modified: 2023.04.01).
11+
* This file: The loader (last modified: 2023.04.03).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -760,17 +760,25 @@ public function timeFormat(int $Time, $In)
760760

761761
/**
762762
* Replaces encapsulated substrings within a string using the values of the
763-
* corresponding elements within the supplied array.
763+
* corresponding elements within an array.
764764
*
765765
* @param array $Needles An array containing replacement values.
766766
* @param string $Haystack The string to work with.
767+
* @param bool $L10N Whether to parse L10N placeholders found in the haystack.
767768
* @return string The string with its encapsulated substrings replaced.
768769
*/
769-
public function parse(array $Needles, string $Haystack): string
770+
public function parse(array $Needles, string $Haystack = '', bool $L10N = false): string
770771
{
771-
if (empty($Haystack)) {
772+
if ($Haystack === '') {
772773
return '';
773774
}
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+
}
774782
foreach ($Needles as $Key => $Value) {
775783
if (!is_array($Value) && $Value !== null) {
776784
$Haystack = str_replace('{' . $Key . '}', $Value, $Haystack);

0 commit comments

Comments
 (0)