Skip to content

Commit

Permalink
Remove sanitize() method and add regex to existing $resultRegexes
Browse files Browse the repository at this point in the history
… array.

Addition to #199
  • Loading branch information
Stichoza committed Dec 18, 2023
1 parent 9e2e66b commit 32cd497
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/GoogleTranslate.php
Expand Up @@ -96,6 +96,7 @@ class GoogleTranslate
protected array $resultRegexes = [
'/,+/' => ',',
'/\[,/' => '[',
'/\xc2\xa0/' => ' ',
];

/**
Expand Down Expand Up @@ -303,7 +304,7 @@ public function translate(string $string): ?string
$output = (string) $responseArray[0];
}

return $this->injectParameters($this->sanitize($output), $replacements);
return $this->injectParameters($output, $replacements);
}

/**
Expand Down Expand Up @@ -385,17 +386,6 @@ protected function getParameters(string $string): array
return $matches[0];
}

/**
* Cleans up weird spaces returned from Google Translate.
*
* @param string $string
* @return string
*/
protected function sanitize(string $string): string
{
return preg_replace('/\xc2\xa0/', ' ', $string);
}

/**
* Get response array.
*
Expand Down

0 comments on commit 32cd497

Please sign in to comment.