Skip to content

feat(translate): upgrade google/cloud-translate to ^2.0 - #2345

Merged
bshaffer merged 2 commits into
mainfrom
translate/upgrade-v2
Nov 6, 2026
Merged

bshaffer merged 2 commits into
mainfrom
translate/upgrade-v2

Conversation

@bshaffer

@bshaffer bshaffer commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Upgrade our Translate samples to google/cloud-translate v2:

  • Update google/cloud-translate and google/cloud-storage to ^2.0
  • Migrate translate/quickstart.php from the removed V2 TranslateClient to V3
  • Remove legacy V2 samples that already have V3 equivalents

@snippet-bot

snippet-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to delete 5 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added api: translate Issues related to the Cloud Translation API. samples Issues that are directly related to samples. labels Nov 6, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request upgrades the Google Cloud Translate PHP samples from V2 to V3. Key changes include updating dependencies in composer.json to ^2.0, refactoring quickstart.php to use TranslationServiceClient and TranslateTextRequest, deleting legacy V2 sample files, and updating the corresponding tests and documentation. Feedback was provided on quickstart.php to improve output formatting readability by replacing the multiline string literal with printf and PHP_EOL.

Comment thread translate/quickstart.php
Comment on lines +44 to +47
foreach ($response->getTranslations() as $translation) {
echo 'Text: ' . $text . '
Translation: ' . $translation->getTranslatedText();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current output formatting uses a multiline string literal that lacks a trailing newline and can be difficult to read or maintain due to indentation. Using printf with PHP_EOL improves readability, ensures consistent newlines, and avoids formatting issues.

foreach ($response->getTranslations() as $translation) {
    printf('Text: %s' . PHP_EOL, $text);
    printf('Translation: %s' . PHP_EOL, $translation->getTranslatedText());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: translate Issues related to the Cloud Translation API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant