Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use GoogleCloudCoreServiceBuilder;
- use GoogleCloudLanguageLanguageClient;
- use GoogleCloudCoreExceptionBadRequestException;
- class Google_natural_language
- {
- protected $cloud;
- protected $translate;
- public function __construct()
- {
- // parent::__construct();
- // Authenticate using a keyfile path
- $this->cloud = new ServiceBuilder([
- 'keyFilePath' => APPPATH.'third_party/service_account.json'
- ]);
- }
- public function translate($text, $target='en')
- {
- $this->translate = $this->cloud->translate();
- try {
- //
- $translation = $this->translate->translate($text, [
- 'target' => $target
- ]);
- } catch (BadRequestException $e) {
- dblog_message('ERROR', $e);
- return false;
- }
- return $translation;
- }
- }
Add Comment
Please, Sign In to add comment