From f47197b1cd14bb1d8d934523af3a4f29a9ec9709 Mon Sep 17 00:00:00 2001 From: Chitzi Ltd Date: Wed, 26 Jun 2024 10:39:30 +0300 Subject: [PATCH] Remove space in the parameters Google adds in some language some space inside the parameters (ex. #{ 21}), this will remove it before parsing it. --- src/GoogleTranslate.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GoogleTranslate.php b/src/GoogleTranslate.php index efc1e37..c70115f 100644 --- a/src/GoogleTranslate.php +++ b/src/GoogleTranslate.php @@ -364,6 +364,9 @@ function ($matches) { */ protected function injectParameters(string $string, array $replacements): string { + // Remove space added by google in the parameters + $string = preg_replace('/#\{\s*(\d+)\s*\}/', '#{$1}', $string); + return preg_replace_callback( '/\#{(\d+)}/', fn($matches) => $replacements[$matches[1]],