Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: promote Translate to v2 #7903

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 12 additions & 43 deletions Core/src/ServiceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
use Google\Cloud\Speech\SpeechClient;
use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Trace\TraceClient;
use Google\Cloud\Translate\V2\TranslateClient;
use Google\Cloud\Translate\V2\TranslateClient as DeprecatedTranslateClient;
use Google\Cloud\Translate\V3\Client\TranslationServiceClient;
use Google\Cloud\Vision\VisionClient;
use Psr\Cache\CacheItemPoolInterface;

Expand Down Expand Up @@ -356,51 +357,19 @@ public function vision(array $config = [])
}

/**
* Google Cloud Translation provides the ability to dynamically translate
* text between thousands of language pairs and lets websites and programs
* integrate with translation service programmatically.
*
* The Google Cloud Translation API is available as a paid
* service. See the [Pricing](https://cloud.google.com/translation/v2/pricing)
* and [FAQ](https://cloud.google.com/translation/v2/faq) pages for details.
* Find more information at the the
* [Google Cloud Translation docs](https://cloud.google.com/translation/docs/).
*
* Please note that while the Google Cloud Translation API supports
* authentication via service account and application default credentials
* like other Cloud Platform APIs, it also supports authentication via a
* public API access key. If you wish to authenticate using an API key,
* follow the
* [before you begin](https://cloud.google.com/translation/v2/translating-text-with-rest#before-you-begin)
* instructions to learn how to generate a key.
*
* Example:
* ```
* use Google\Cloud\Core\ServiceBuilder;
*
* $builder = new ServiceBuilder([
* 'key' => 'YOUR_KEY'
* ]);
*
* $translate = $builder->translate();
* ```
*
* @param array $config [optional] {
* Configuration options.
*
* @type string $key A public API access key.
* @type string $target The target language to assign to the client.
* Defaults to `en` (English).
* @type callable $httpHandler A handler used to deliver Psr7 requests.
* Only valid for requests sent over REST.
* @type int $retries Number of retries for a failed request.
* **Defaults to** `3`.
* }
* @return TranslateClient
* @deprecated
* @see TranslationServiceClient
* @throws \BadMethodCallException
*/
public function translate(array $config = [])
{
return $this->createClient(TranslateClient::class, 'translate', $config);
if (class_exists(DeprecatedTranslateClient::class)) {
return $this->createClient(DeprecatedTranslateClient::class, 'translate', $config);
}
throw new \BadMethodCallException(sprintf(
'This method is no longer supported, create %s directly instead.',
TranslationServiceClient::class
));
}

/**
Expand Down
2 changes: 0 additions & 2 deletions Core/tests/Snippet/ServiceBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Google\Cloud\Speech\SpeechClient;
use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Trace\TraceClient;
use Google\Cloud\Translate\TranslateClient;
use Google\Cloud\Vision\VisionClient;

/**
Expand Down Expand Up @@ -64,7 +63,6 @@ public function serviceBuilderMethods()
['storage', StorageClient::class, 'storage'],
['trace', TraceClient::class, 'trace'],
['vision', VisionClient::class, 'vision'],
['translate', TranslateClient::class, 'translate']
];
}

Expand Down
15 changes: 0 additions & 15 deletions Core/tests/Unit/ServiceBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use Google\Cloud\Speech\SpeechClient;
use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Core\Tests\Unit\Fixtures;
use Google\Cloud\Translate\TranslateClient;
use Google\Cloud\Vision\VisionClient;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -68,17 +67,6 @@ public function testBuildsClients($serviceName, $expectedClient, array $args = [
$this->assertInstanceOf($expectedClient, $localConfigClient);
}

public function testTranslateClientWithApiKey()
{
$this->checkAndSkipTest([TranslateClient::class]);

$config = ['key' => 'test_key'];
$serviceBuilder = new ServiceBuilder($config);

$this->assertInstanceOf(TranslateClient::class, $serviceBuilder->translate());
$this->assertInstanceOf(TranslateClient::class, $serviceBuilder->translate($config));
}

/**
* @dataProvider serviceProvider
*/
Expand Down Expand Up @@ -187,9 +175,6 @@ public function serviceProvider()
], [
'storage',
StorageClient::class
], [
'translate',
TranslateClient::class
], [
'vision',
VisionClient::class
Expand Down
2 changes: 0 additions & 2 deletions Core/tests/Unit/ServicesNotFoundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ private static function getApis()
"Speech",
"Storage",
"Trace",
"Translate",
"VideoIntelligence",
"Vision",
];
Expand All @@ -93,7 +92,6 @@ public function serviceBuilderMethods()
['storage'],
['trace'],
['vision'],
['translate']
];
}

Expand Down
60 changes: 23 additions & 37 deletions Translate/owlbot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019 Google LLC
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,41 +30,27 @@
# Added so that we can pass copy_excludes in the owlbot_main() call
_tracked_paths.add(src)

php.owlbot_main(
src=src,
dest=dest,
copy_excludes=[
src / "*/src/V2/TranslateClient.php"
]
)
# Change the wording for the deprecation warning.
s.replace(
'src/*/*_*.php',
r'will be removed in the next major release',
'will be removed in a future release')

### [START] protoc backwards compatibility fixes

# roll back to private properties.
s.replace(
"src/**/V*/**/*.php",
r"Generated from protobuf field ([^\n]{0,})\n\s{5}\*/\n\s{4}protected \$",
r"""Generated from protobuf field \1
*/
private $""")

# Replace "Unwrapped" with "Value" for method names.
s.replace(
"src/**/V*/**/*.php",
r"public function ([s|g]\w{3,})Unwrapped",
r"public function \1Value"
)

### [END] protoc backwards compatibility fixes
php.owlbot_main(src=src, dest=dest)

# fix relative cloud.google.com links
# remove class_alias code
s.replace(
"src/**/V*/**/*.php",
r"(.{0,})\]\((/.{0,})\)",
r"\1](https://cloud.google.com\2)"
)
"src/V*/**/*.php",
r"^// Adding a class alias for backwards compatibility with the previous class name.$"
+ "\n"
+ r"^class_alias\(.*\);$"
+ "\n",
'')

# format generated clients
subprocess.run([
'npm',
'exec',
'--yes',
'--package=@prettier/plugin-php@^0.16',
'--',
'prettier',
'**/Client/*',
'--write',
'--parser=php',
'--single-quote',
'--print-width=120'])
16 changes: 0 additions & 16 deletions Translate/phpunit-snippets.xml.dist

This file was deleted.

40 changes: 0 additions & 40 deletions Translate/src/Connection/ConnectionInterface.php

This file was deleted.

40 changes: 0 additions & 40 deletions Translate/src/Connection/Rest.php

This file was deleted.

38 changes: 0 additions & 38 deletions Translate/src/TranslateClient.php

This file was deleted.

50 changes: 0 additions & 50 deletions Translate/src/V2/Connection/ConnectionInterface.php

This file was deleted.

Loading
Loading