- Added array return type if key is incomplete

This commit is contained in:
mcndave committed 2020-10-06 16:00:27 +00:00
1 parent 026126be76
commit 86603044c0
3 files changed
+25 -57

No files matched your search

+8 -8
View File
@@ -44,16 +44,16 @@ class I18n implements MissingKeyInterface
return $loaded;
}
public function fromKey(string $key, array $variables) : ?string
public function fromKey(string $key, array $variables) # : ?string|array
{
if ( null === ( $string = $this->get($key) ) ) {
$string = $this->missingKey ? $this->missingKey->get($key) : null;
$string = $this->missingKey ? $this->missingKey->get($key) : null;
}
if (is_array($string)) {
$string = json_encode($string);
}
#if (is_array($string)) {
# $string = json_encode($string);
#}
return $string && $variables ? $this->placeVariables($string, $variables) : $string;
}
@@ -130,7 +130,7 @@ class I18n implements MissingKeyInterface
}
protected function placeVariables(string $string, array $parameters) {
if ( preg_match_all('~{$(.*?)}~si', $string, $matches, PREG_SET_ORDER) ) {
if ( preg_match_all('~\\{\\$(.*?)\\}~si', $string, $matches, PREG_SET_ORDER) ) {
$search = [];
foreach($matches as $item) {