diff --git a/config/googletranslate.php b/config/googletranslate.php index b07327e..0639db1 100644 --- a/config/googletranslate.php +++ b/config/googletranslate.php @@ -1,21 +1,21 @@ 'en', + /* + |---------------------------------------------------------------------------------------------------- + | The ISO 639-1 code of the language in lowercase to which the text will be translated to by default. + |---------------------------------------------------------------------------------------------------- + */ + 'default_target_translation' => 'en', - /* - |------------------------------------------------------------------------------- - | Api Key generated within Google Cloud Dashboard. - | - | The process to get this file is documented in a step by step detailed manner - | over here: - | https://github.com/JoggApp/laravel-google-translate/blob/master/google.md - |------------------------------------------------------------------------------- - */ - 'api_key' => env('GOOGLE_TRANSLATE_API_KEY'), + /* + |------------------------------------------------------------------------------- + | Api Key generated within Google Cloud Dashboard. + | + | The process to get this file is documented in a step by step detailed manner + | over here: + | https://github.com/JoggApp/laravel-google-translate/blob/master/google.md + |------------------------------------------------------------------------------- + */ + 'api_key' => env('GOOGLE_TRANSLATE_API_KEY'), ]; diff --git a/src/GoogleTranslateClient.php b/src/GoogleTranslateClient.php index 86b2f7b..a18d425 100644 --- a/src/GoogleTranslateClient.php +++ b/src/GoogleTranslateClient.php @@ -8,66 +8,65 @@ class GoogleTranslateClient { - use SupportedLanguages; + use SupportedLanguages; - private $translate; + private $translate; - public function __construct(array $config) - { - $this->checkForInvalidConfiguration($config); - - $this->translate = new TranslateClient([ - 'key' => $config['api_key'] - ]); - } - - public function detectLanguage(string $text) - { - return $this->translate - ->detectLanguage($text); - } + public function __construct(array $config) + { + $this->checkForInvalidConfiguration($config); + $this->translate = new TranslateClient([ + 'key' => $config['api_key'], + ]); + } - public function detectLanguageBatch(array $input) - { - return $this->translate - ->detectLanguageBatch($input); - } + public function detectLanguage(string $text) + { + return $this->translate + ->detectLanguage($text); + } - public function translate(string $text, string $translateTo, string $format = 'text') - { - return $this->translate - ->translate($text, ['target' => $translateTo, 'format' => $format]); - } + public function detectLanguageBatch(array $input) + { + return $this->translate + ->detectLanguageBatch($input); + } - public function translateBatch(array $input, string $translateTo, string $format = 'text') - { - return $this->translate - ->translateBatch($input, ['target' => $translateTo, 'format' => $format]); - } + public function translate(string $text, string $translateTo, string $format = 'text') + { + return $this->translate + ->translate($text, ['target' => $translateTo, 'format' => $format]); + } - public function getAvaliableTranslationsFor(string $languageCode) - { - return $this->translate - ->localizedLanguages(['target' => $languageCode]); - } + public function translateBatch(array $input, string $translateTo, string $format = 'text') + { + return $this->translate + ->translateBatch($input, ['target' => $translateTo, 'format' => $format]); + } - private function checkForInvalidConfiguration(array $config) - { - if (!isset($config['api_key']) || $config['api_key'] === null) { - throw new Exception('Google Api Key is required.'); + public function getAvaliableTranslationsFor(string $languageCode) + { + return $this->translate + ->localizedLanguages(['target' => $languageCode]); } - $codeInConfig = $config['default_target_translation']; + private function checkForInvalidConfiguration(array $config) + { + if ( ! isset($config['api_key']) || $config['api_key'] === null) { + throw new Exception('Google Api Key is required.'); + } + + $codeInConfig = $config['default_target_translation']; - $languageCodeIsValid = is_string($codeInConfig) - && ctype_lower($codeInConfig) - && in_array($codeInConfig, $this->languages()); + $languageCodeIsValid = is_string($codeInConfig) + && ctype_lower($codeInConfig) + && in_array($codeInConfig, $this->languages()); - if (!$languageCodeIsValid) { - throw new Exception( - 'The default_target_translation value in the config/googletranslate.php file should + if ( ! $languageCodeIsValid) { + throw new Exception( + 'The default_target_translation value in the config/googletranslate.php file should be a valid lowercase ISO 639-1 code of the language' - ); + ); + } } - } }