+ */
+ private array $globalTranslatedParameters = [];
+
/**
* @throws InvalidArgumentException If a locale contains invalid characters
*/
@@ -155,6 +165,17 @@ public function getFallbackLocales(): array
return $this->fallbackLocales;
}
+ public function addGlobalParameter(string $id, string|int|float|TranslatableInterface $value): void
+ {
+ $this->globalParameters[$id] = $value;
+ $this->globalTranslatedParameters = [];
+ }
+
+ public function getGlobalParameters(): array
+ {
+ return $this->globalParameters;
+ }
+
public function trans(?string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string
{
if (null === $id || '' === $id) {
@@ -174,7 +195,24 @@ public function trans(?string $id, array $parameters = [], ?string $domain = nul
}
}
- $parameters = array_map(fn ($parameter) => $parameter instanceof TranslatableInterface ? $parameter->trans($this, $locale) : $parameter, $parameters);
+ foreach ($parameters as $key => $value) {
+ if ($value instanceof TranslatableInterface) {
+ $parameters[$key] = $value->trans($this, $locale);
+ }
+ }
+
+ if (null === $globalParameters =& $this->globalTranslatedParameters[$locale]) {
+ $globalParameters = $this->globalParameters;
+ foreach ($globalParameters as $key => $value) {
+ if ($value instanceof TranslatableInterface) {
+ $globalParameters[$key] = $value->trans($this, $locale);
+ }
+ }
+ }
+
+ if ($globalParameters) {
+ $parameters += $globalParameters;
+ }
$len = \strlen(MessageCatalogue::INTL_DOMAIN_SUFFIX);
if ($this->hasIntlFormatter
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy