diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..46b2a08e --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,43 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, +and in the interest of fostering an open and welcoming community, +we pledge to respect all people who contribute through reporting issues, +posting feature requests, updating documentation, +submitting pull requests or patches, and other activities. + +We are committed to making participation in this project +a harassment-free experience for everyone, +regardless of level of experience, gender, gender identity and expression, +sexual orientation, disability, personal appearance, +body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery +* Personal attacks +* Trolling or insulting/derogatory comments +* Public or private harassment +* Publishing other's private information, +such as physical or electronic +addresses, without explicit permission +* Other unethical or unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct. +By adopting this Code of Conduct, +project maintainers commit themselves to fairly and consistently +applying these principles to every aspect of managing this project. +Project maintainers who do not follow or enforce the Code of Conduct +may be permanently removed from the project team. + +This code of conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior +may be reported by opening an issue +or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, +available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..78aaa61b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,55 @@ +# How to become a contributor and submit your own code + +**Table of contents** + +* [Contributor License Agreements](#contributor-license-agreements) +* [Contributing a patch](#contributing-a-patch) +* [Running the tests](#running-the-tests) +* [Releasing the library](#releasing-the-library) + +## Contributor License Agreements + +We'd love to accept your sample apps and patches! Before we can take them, we +have to jump a couple of legal hurdles. + +Please fill out either the individual or corporate Contributor License Agreement +(CLA). + + * If you are an individual writing original source code and you're sure you + own the intellectual property, then you'll need to sign an [individual CLA](https://developers.google.com/open-source/cla/individual). + * If you work for a company that wants to allow you to contribute your work, + then you'll need to sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). + +Follow either of the two links above to access the appropriate CLA and +instructions for how to sign and return it. Once we receive it, we'll be able to +accept your pull requests. + +## Contributing A Patch + +1. Submit an issue describing your proposed change to the repo in question. +1. The repo owner will respond to your issue promptly. +1. If your proposed change is accepted, and you haven't already done so, sign a + Contributor License Agreement (see details above). +1. Fork the desired repo, develop and test your code changes. +1. Ensure that your code adheres to the existing style in the code to which + you are contributing. +1. Ensure that your code has an appropriate set of tests which all pass. +1. Submit a pull request. + +## Running the tests + +1. [Prepare your environment for Node.js setup][setup]. + +1. Install dependencies: + + npm install + +1. Run the tests: + + npm test + +1. Lint (and maybe fix) any changes: + + npm run fix + +[setup]: https://cloud.google.com/nodejs/docs/setup diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..8b58ae9c --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,7 @@ +# Security Policy + +To report a security issue, please use [g.co/vulnz](https://g.co/vulnz). + +The Google Security Team will respond within 5 working days of your report on g.co/vulnz. + +We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue. diff --git a/owlbot.py b/owlbot.py deleted file mode 100644 index 49fce7a6..00000000 --- a/owlbot.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the License); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import synthtool.languages.node as node -node.owlbot_main(templates_excludes=[ -'README.md' -]) diff --git a/samples/.eslintrc.yml b/samples/.eslintrc.yml deleted file mode 100644 index 282535f5..00000000 --- a/samples/.eslintrc.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -rules: - no-console: off diff --git a/samples/README.md b/samples/README.md deleted file mode 100644 index 1bc6651d..00000000 --- a/samples/README.md +++ /dev/null @@ -1,152 +0,0 @@ -[//]: # "This README.md file is auto-generated, all changes to this file will be lost." -[//]: # "To regenerate it, use `python -m synthtool`." -Google Cloud Platform logo - -# [Cloud Translation: Node.js Samples](https://github.com/googleapis/nodejs-translate) - -[![Open in Cloud Shell][shell_img]][shell_link] - -The [Cloud Translation API](https://cloud.google.com/translate/docs/), -can dynamically translate text between thousands -of language pairs. The Cloud Translation API lets websites and programs -integrate with the translation service programmatically. The Cloud Translation -API is part of the larger Cloud Machine Learning API family. - -## Table of Contents - -* [Before you begin](#before-you-begin) -* [Samples](#samples) - * [Hybrid Glossaries](#hybrid-glossaries) - * [Quickstart](#quickstart) - * [Translate](#translate) - -## Before you begin - -Before running the samples, make sure you've followed the steps outlined in -[Using the client library](https://github.com/googleapis/nodejs-translate#using-the-client-library). - -### Choosing between Advanced v3 and Basic v2 - -Basic supports language detection and text translation [Cloud Translation - Basic v2](https://cloud.google.com/translate/docs/editions#basic). - -The advanced edition of [Cloud Translation - V3](https://cloud.google.com/translate/docs/editions#advanced) is optimized for customization and long form content use cases including glossary, batch, and model selection. - -### Translate V3 Beta Samples - -#### Install Dependencies - -From the [root directory](https://github.com/googleapis/nodejs-translate) of the client library install the dependencies: - -``` -npm install -``` - -Change to the samples directory, link the google-cloud/translate library from the parent, and install its dependencies: - -``` -cd samples/ -npm link ../ -npm install -``` - -#### Run the Tests - -To run the tests for the entire sample, run - -``` -npm test -``` - -To run the tests for only the translate v3 samples, run - -``` -npm run test-v3 -``` - -To run the tests for a single translate v3 sample, run this command, substituting FILE_NAME with the name of a valid test file. - -``` -./node_modules/.bin/mocha test/v3beta1/FILE_NAME -``` - -For example, to test the `translate_list_language_names_beta` sample, the command would be - -``` -./node_modules/.bin/mocha test/v3beta1/translate_list_language_names_beta.test.js -``` - -To run a sample directly, call the file with the `node` command and any required CLI arguments: - -``` -node v3beta1/FILE_NAME -``` - -For example, to run the `translate_list_codes_beta` sample, you would run the following command, substituting your project ID in place of "your_project_id" - -``` -node v3beta1/translate_list_codes_beta.js "your_project_id" -``` - -`cd samples` - -`npm install` - -`cd ..` - -## Samples - - - -### Hybrid Glossaries - -View the [source code](https://github.com/googleapis/nodejs-translate/blob/main/samples/hybridGlossaries.js). - -[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-translate&page=editor&open_in_editor=samples/hybridGlossaries.js,samples/README.md) - -__Usage:__ - - -`node samples/hybridGlossaries.js` - - ------ - - - - -### Quickstart - -View the [source code](https://github.com/googleapis/nodejs-translate/blob/main/samples/quickstart.js). - -[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-translate&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) - -__Usage:__ - - -`node samples/quickstart.js` - - ------ - - - - -### Translate - -View the [source code](https://github.com/googleapis/nodejs-translate/blob/main/samples/translate.js). - -[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-translate&page=editor&open_in_editor=samples/translate.js,samples/README.md) - -__Usage:__ - - -`node samples/translate.js` - - - - - - -[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png -[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-translate&page=editor&open_in_editor=samples/README.md -[product-docs]: https://cloud.google.com/translate/docs/ diff --git a/samples/generated/v3/snippet_metadata.google.cloud.translation.v3.json b/samples/generated/v3/snippet_metadata.google.cloud.translation.v3.json deleted file mode 100644 index 26f3106c..00000000 --- a/samples/generated/v3/snippet_metadata.google.cloud.translation.v3.json +++ /dev/null @@ -1,567 +0,0 @@ -{ - "clientLibrary": { - "name": "nodejs-translation", - "version": "7.0.4", - "language": "TYPESCRIPT", - "apis": [ - { - "id": "google.cloud.translation.v3", - "version": "v3" - } - ] - }, - "snippets": [ - { - "regionTag": "translate_v3_generated_TranslationService_TranslateText_async", - "title": "TranslationService translateText Sample", - "origin": "API_DEFINITION", - "description": " Translates input text and returns translated text.", - "canonical": true, - "file": "translation_service.translate_text.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 118, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "TranslateText", - "fullName": "google.cloud.translation.v3.TranslationService.TranslateText", - "async": true, - "parameters": [ - { - "name": "contents", - "type": "TYPE_STRING[]" - }, - { - "name": "mime_type", - "type": "TYPE_STRING" - }, - { - "name": "source_language_code", - "type": "TYPE_STRING" - }, - { - "name": "target_language_code", - "type": "TYPE_STRING" - }, - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "model", - "type": "TYPE_STRING" - }, - { - "name": "glossary_config", - "type": ".google.cloud.translation.v3.TranslateTextGlossaryConfig" - }, - { - "name": "labels", - "type": "TYPE_MESSAGE[]" - } - ], - "resultType": ".google.cloud.translation.v3.TranslateTextResponse", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3.TranslationServiceClient" - }, - "method": { - "shortName": "TranslateText", - "fullName": "google.cloud.translation.v3.TranslationService.TranslateText", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3_generated_TranslationService_DetectLanguage_async", - "title": "TranslationService detectLanguage Sample", - "origin": "API_DEFINITION", - "description": " Detects the language of text within a request.", - "canonical": true, - "file": "translation_service.detect_language.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 88, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "DetectLanguage", - "fullName": "google.cloud.translation.v3.TranslationService.DetectLanguage", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "model", - "type": "TYPE_STRING" - }, - { - "name": "content", - "type": "TYPE_STRING" - }, - { - "name": "mime_type", - "type": "TYPE_STRING" - }, - { - "name": "labels", - "type": "TYPE_MESSAGE[]" - } - ], - "resultType": ".google.cloud.translation.v3.DetectLanguageResponse", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3.TranslationServiceClient" - }, - "method": { - "shortName": "DetectLanguage", - "fullName": "google.cloud.translation.v3.TranslationService.DetectLanguage", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3_generated_TranslationService_GetSupportedLanguages_async", - "title": "TranslationService getSupportedLanguages Sample", - "origin": "API_DEFINITION", - "description": " Returns a list of supported languages for translation.", - "canonical": true, - "file": "translation_service.get_supported_languages.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 78, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "GetSupportedLanguages", - "fullName": "google.cloud.translation.v3.TranslationService.GetSupportedLanguages", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "display_language_code", - "type": "TYPE_STRING" - }, - { - "name": "model", - "type": "TYPE_STRING" - } - ], - "resultType": ".google.cloud.translation.v3.SupportedLanguages", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3.TranslationServiceClient" - }, - "method": { - "shortName": "GetSupportedLanguages", - "fullName": "google.cloud.translation.v3.TranslationService.GetSupportedLanguages", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3_generated_TranslationService_TranslateDocument_async", - "title": "TranslationService translateDocument Sample", - "origin": "API_DEFINITION", - "description": " Translates documents in synchronous mode.", - "canonical": true, - "file": "translation_service.translate_document.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 115, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "TranslateDocument", - "fullName": "google.cloud.translation.v3.TranslationService.TranslateDocument", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "source_language_code", - "type": "TYPE_STRING" - }, - { - "name": "target_language_code", - "type": "TYPE_STRING" - }, - { - "name": "document_input_config", - "type": ".google.cloud.translation.v3.DocumentInputConfig" - }, - { - "name": "document_output_config", - "type": ".google.cloud.translation.v3.DocumentOutputConfig" - }, - { - "name": "model", - "type": "TYPE_STRING" - }, - { - "name": "glossary_config", - "type": ".google.cloud.translation.v3.TranslateTextGlossaryConfig" - }, - { - "name": "labels", - "type": "TYPE_MESSAGE[]" - } - ], - "resultType": ".google.cloud.translation.v3.TranslateDocumentResponse", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3.TranslationServiceClient" - }, - "method": { - "shortName": "TranslateDocument", - "fullName": "google.cloud.translation.v3.TranslationService.TranslateDocument", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3_generated_TranslationService_BatchTranslateText_async", - "title": "TranslationService batchTranslateText Sample", - "origin": "API_DEFINITION", - "description": " Translates a large volume of text in asynchronous batch mode. This function provides real-time output as the inputs are being processed. If caller cancels a request, the partial results (for an input file, it's all or nothing) may still be available on the specified output location. This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call.", - "canonical": true, - "file": "translation_service.batch_translate_text.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 112, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "BatchTranslateText", - "fullName": "google.cloud.translation.v3.TranslationService.BatchTranslateText", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "source_language_code", - "type": "TYPE_STRING" - }, - { - "name": "target_language_codes", - "type": "TYPE_STRING[]" - }, - { - "name": "models", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "input_configs", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "output_config", - "type": ".google.cloud.translation.v3.OutputConfig" - }, - { - "name": "glossaries", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "labels", - "type": "TYPE_MESSAGE[]" - } - ], - "resultType": ".google.longrunning.Operation", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3.TranslationServiceClient" - }, - "method": { - "shortName": "BatchTranslateText", - "fullName": "google.cloud.translation.v3.TranslationService.BatchTranslateText", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3_generated_TranslationService_BatchTranslateDocument_async", - "title": "TranslationService batchTranslateDocument Sample", - "origin": "API_DEFINITION", - "description": " Translates a large volume of document in asynchronous batch mode. This function provides real-time output as the inputs are being processed. If caller cancels a request, the partial results (for an input file, it's all or nothing) may still be available on the specified output location. This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call.", - "canonical": true, - "file": "translation_service.batch_translate_document.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 115, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "BatchTranslateDocument", - "fullName": "google.cloud.translation.v3.TranslationService.BatchTranslateDocument", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "source_language_code", - "type": "TYPE_STRING" - }, - { - "name": "target_language_codes", - "type": "TYPE_STRING[]" - }, - { - "name": "input_configs", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "output_config", - "type": ".google.cloud.translation.v3.BatchDocumentOutputConfig" - }, - { - "name": "models", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "glossaries", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "format_conversions", - "type": "TYPE_MESSAGE[]" - } - ], - "resultType": ".google.longrunning.Operation", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3.TranslationServiceClient" - }, - "method": { - "shortName": "BatchTranslateDocument", - "fullName": "google.cloud.translation.v3.TranslationService.BatchTranslateDocument", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3_generated_TranslationService_CreateGlossary_async", - "title": "TranslationService createGlossary Sample", - "origin": "API_DEFINITION", - "description": " Creates a glossary and returns the long-running operation. Returns NOT_FOUND, if the project doesn't exist.", - "canonical": true, - "file": "translation_service.create_glossary.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 59, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "CreateGlossary", - "fullName": "google.cloud.translation.v3.TranslationService.CreateGlossary", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "glossary", - "type": ".google.cloud.translation.v3.Glossary" - } - ], - "resultType": ".google.longrunning.Operation", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3.TranslationServiceClient" - }, - "method": { - "shortName": "CreateGlossary", - "fullName": "google.cloud.translation.v3.TranslationService.CreateGlossary", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3_generated_TranslationService_ListGlossaries_async", - "title": "TranslationService listGlossaries Sample", - "origin": "API_DEFINITION", - "description": " Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't exist.", - "canonical": true, - "file": "translation_service.list_glossaries.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 86, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "ListGlossaries", - "fullName": "google.cloud.translation.v3.TranslationService.ListGlossaries", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "page_size", - "type": "TYPE_INT32" - }, - { - "name": "page_token", - "type": "TYPE_STRING" - }, - { - "name": "filter", - "type": "TYPE_STRING" - } - ], - "resultType": ".google.cloud.translation.v3.ListGlossariesResponse", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3.TranslationServiceClient" - }, - "method": { - "shortName": "ListGlossaries", - "fullName": "google.cloud.translation.v3.TranslationService.ListGlossaries", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3_generated_TranslationService_GetGlossary_async", - "title": "TranslationService getGlossary Sample", - "origin": "API_DEFINITION", - "description": " Gets a glossary. Returns NOT_FOUND, if the glossary doesn't exist.", - "canonical": true, - "file": "translation_service.get_glossary.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 53, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "GetGlossary", - "fullName": "google.cloud.translation.v3.TranslationService.GetGlossary", - "async": true, - "parameters": [ - { - "name": "name", - "type": "TYPE_STRING" - } - ], - "resultType": ".google.cloud.translation.v3.Glossary", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3.TranslationServiceClient" - }, - "method": { - "shortName": "GetGlossary", - "fullName": "google.cloud.translation.v3.TranslationService.GetGlossary", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3_generated_TranslationService_DeleteGlossary_async", - "title": "TranslationService deleteGlossary Sample", - "origin": "API_DEFINITION", - "description": " Deletes a glossary, or cancels glossary construction if the glossary isn't created yet. Returns NOT_FOUND, if the glossary doesn't exist.", - "canonical": true, - "file": "translation_service.delete_glossary.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 54, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "DeleteGlossary", - "fullName": "google.cloud.translation.v3.TranslationService.DeleteGlossary", - "async": true, - "parameters": [ - { - "name": "name", - "type": "TYPE_STRING" - } - ], - "resultType": ".google.longrunning.Operation", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3.TranslationServiceClient" - }, - "method": { - "shortName": "DeleteGlossary", - "fullName": "google.cloud.translation.v3.TranslationService.DeleteGlossary", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3.TranslationService" - } - } - } - } - ] -} \ No newline at end of file diff --git a/samples/generated/v3/translation_service.batch_translate_document.js b/samples/generated/v3/translation_service.batch_translate_document.js deleted file mode 100644 index eb48f979..00000000 --- a/samples/generated/v3/translation_service.batch_translate_document.js +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) { - // [START translate_v3_generated_TranslationService_BatchTranslateDocument_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. Location to make a regional call. - * Format: `projects/{project-number-or-id}/locations/{location-id}`. - * The `global` location is not supported for batch translation. - * Only AutoML Translation models or glossaries within the same region (have - * the same location-id) can be used, otherwise an INVALID_ARGUMENT (400) - * error is returned. - */ - // const parent = 'abc123' - /** - * Required. The BCP-47 language code of the input document if known, for - * example, "en-US" or "sr-Latn". Supported language codes are listed in - * Language Support (https://cloud.google.com/translate/docs/languages). - */ - // const sourceLanguageCode = 'abc123' - /** - * Required. The BCP-47 language code to use for translation of the input - * document. Specify up to 10 language codes here. - */ - // const targetLanguageCodes = 'abc123' - /** - * Required. Input configurations. - * The total number of files matched should be <= 100. - * The total content size to translate should be <= 100M Unicode codepoints. - * The files must use UTF-8 encoding. - */ - // const inputConfigs = 1234 - /** - * Required. Output configuration. - * If 2 input configs match to the same file (that is, same input path), - * we don't generate output for duplicate inputs. - */ - // const outputConfig = {} - /** - * Optional. The models to use for translation. Map's key is target language - * code. Map's value is the model name. Value can be a built-in general model, - * or an AutoML Translation model. - * The value format depends on model type: - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * If the map is empty or a specific model is - * not requested for a language pair, then default google model (nmt) is used. - */ - // const models = 1234 - /** - * Optional. Glossaries to be applied. It's keyed by target language code. - */ - // const glossaries = 1234 - /** - * Optional. File format conversion map to be applied to all input files. - * Map's key is the original mime_type. Map's value is the target mime_type of - * translated documents. - * Supported file format conversion includes: - * - `application/pdf` to - * `application/vnd.openxmlformats-officedocument.wordprocessingml.document` - * If nothing specified, output files will be in the same format as the - * original file. - */ - // const formatConversions = 1234 - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callBatchTranslateDocument() { - // Construct request - const request = { - parent, - sourceLanguageCode, - targetLanguageCodes, - inputConfigs, - outputConfig, - }; - - // Run request - const [operation] = await translationClient.batchTranslateDocument(request); - const [response] = await operation.promise(); - console.log(response); - } - - callBatchTranslateDocument(); - // [END translate_v3_generated_TranslationService_BatchTranslateDocument_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3/translation_service.batch_translate_text.js b/samples/generated/v3/translation_service.batch_translate_text.js deleted file mode 100644 index 6e6352ff..00000000 --- a/samples/generated/v3/translation_service.batch_translate_text.js +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) { - // [START translate_v3_generated_TranslationService_BatchTranslateText_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. Location to make a call. Must refer to a caller's project. - * Format: `projects/{project-number-or-id}/locations/{location-id}`. - * The `global` location is not supported for batch translation. - * Only AutoML Translation models or glossaries within the same region (have - * the same location-id) can be used, otherwise an INVALID_ARGUMENT (400) - * error is returned. - */ - // const parent = 'abc123' - /** - * Required. Source language code. - */ - // const sourceLanguageCode = 'abc123' - /** - * Required. Specify up to 10 language codes here. - */ - // const targetLanguageCodes = 'abc123' - /** - * Optional. The models to use for translation. Map's key is target language - * code. Map's value is model name. Value can be a built-in general model, - * or an AutoML Translation model. - * The value format depends on model type: - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * If the map is empty or a specific model is - * not requested for a language pair, then default google model (nmt) is used. - */ - // const models = 1234 - /** - * Required. Input configurations. - * The total number of files matched should be <= 100. - * The total content size should be <= 100M Unicode codepoints. - * The files must use UTF-8 encoding. - */ - // const inputConfigs = 1234 - /** - * Required. Output configuration. - * If 2 input configs match to the same file (that is, same input path), - * we don't generate output for duplicate inputs. - */ - // const outputConfig = {} - /** - * Optional. Glossaries to be applied for translation. - * It's keyed by target language code. - */ - // const glossaries = 1234 - /** - * Optional. The labels with user-defined metadata for the request. - * Label keys and values can be no longer than 63 characters - * (Unicode codepoints), can only contain lowercase letters, numeric - * characters, underscores and dashes. International characters are allowed. - * Label values are optional. Label keys must start with a letter. - * See https://cloud.google.com/translate/docs/advanced/labels for more - * information. - */ - // const labels = 1234 - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callBatchTranslateText() { - // Construct request - const request = { - parent, - sourceLanguageCode, - targetLanguageCodes, - inputConfigs, - outputConfig, - }; - - // Run request - const [operation] = await translationClient.batchTranslateText(request); - const [response] = await operation.promise(); - console.log(response); - } - - callBatchTranslateText(); - // [END translate_v3_generated_TranslationService_BatchTranslateText_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3/translation_service.create_glossary.js b/samples/generated/v3/translation_service.create_glossary.js deleted file mode 100644 index 6851f996..00000000 --- a/samples/generated/v3/translation_service.create_glossary.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent, glossary) { - // [START translate_v3_generated_TranslationService_CreateGlossary_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. The project name. - */ - // const parent = 'abc123' - /** - * Required. The glossary to create. - */ - // const glossary = {} - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callCreateGlossary() { - // Construct request - const request = { - parent, - glossary, - }; - - // Run request - const [operation] = await translationClient.createGlossary(request); - const [response] = await operation.promise(); - console.log(response); - } - - callCreateGlossary(); - // [END translate_v3_generated_TranslationService_CreateGlossary_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3/translation_service.delete_glossary.js b/samples/generated/v3/translation_service.delete_glossary.js deleted file mode 100644 index 3f73f2c4..00000000 --- a/samples/generated/v3/translation_service.delete_glossary.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(name) { - // [START translate_v3_generated_TranslationService_DeleteGlossary_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. The name of the glossary to delete. - */ - // const name = 'abc123' - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callDeleteGlossary() { - // Construct request - const request = { - name, - }; - - // Run request - const [operation] = await translationClient.deleteGlossary(request); - const [response] = await operation.promise(); - console.log(response); - } - - callDeleteGlossary(); - // [END translate_v3_generated_TranslationService_DeleteGlossary_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3/translation_service.detect_language.js b/samples/generated/v3/translation_service.detect_language.js deleted file mode 100644 index 265776c2..00000000 --- a/samples/generated/v3/translation_service.detect_language.js +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent) { - // [START translate_v3_generated_TranslationService_DetectLanguage_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. Project or location to make a call. Must refer to a caller's - * project. - * Format: `projects/{project-number-or-id}/locations/{location-id}` or - * `projects/{project-number-or-id}`. - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * Only models within the same region (has same location-id) can be used. - * Otherwise an INVALID_ARGUMENT (400) error is returned. - */ - // const parent = 'abc123' - /** - * Optional. The language detection model to be used. - * Format: - * `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/{model-id}` - * Only one language detection model is currently supported: - * `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/default`. - * If not specified, the default model is used. - */ - // const model = 'abc123' - /** - * The content of the input stored as a string. - */ - // const content = 'abc123' - /** - * Optional. The format of the source text, for example, "text/html", - * "text/plain". If left blank, the MIME type defaults to "text/html". - */ - // const mimeType = 'abc123' - /** - * Optional. The labels with user-defined metadata for the request. - * Label keys and values can be no longer than 63 characters - * (Unicode codepoints), can only contain lowercase letters, numeric - * characters, underscores and dashes. International characters are allowed. - * Label values are optional. Label keys must start with a letter. - * See https://cloud.google.com/translate/docs/advanced/labels for more - * information. - */ - // const labels = 1234 - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callDetectLanguage() { - // Construct request - const request = { - parent, - }; - - // Run request - const response = await translationClient.detectLanguage(request); - console.log(response); - } - - callDetectLanguage(); - // [END translate_v3_generated_TranslationService_DetectLanguage_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3/translation_service.get_glossary.js b/samples/generated/v3/translation_service.get_glossary.js deleted file mode 100644 index 3b715e01..00000000 --- a/samples/generated/v3/translation_service.get_glossary.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(name) { - // [START translate_v3_generated_TranslationService_GetGlossary_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. The name of the glossary to retrieve. - */ - // const name = 'abc123' - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callGetGlossary() { - // Construct request - const request = { - name, - }; - - // Run request - const response = await translationClient.getGlossary(request); - console.log(response); - } - - callGetGlossary(); - // [END translate_v3_generated_TranslationService_GetGlossary_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3/translation_service.get_supported_languages.js b/samples/generated/v3/translation_service.get_supported_languages.js deleted file mode 100644 index bcc8e78f..00000000 --- a/samples/generated/v3/translation_service.get_supported_languages.js +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent) { - // [START translate_v3_generated_TranslationService_GetSupportedLanguages_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. Project or location to make a call. Must refer to a caller's - * project. - * Format: `projects/{project-number-or-id}` or - * `projects/{project-number-or-id}/locations/{location-id}`. - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * Non-global location is required for AutoML models. - * Only models within the same region (have same location-id) can be used, - * otherwise an INVALID_ARGUMENT (400) error is returned. - */ - // const parent = 'abc123' - /** - * Optional. The language to use to return localized, human readable names - * of supported languages. If missing, then display names are not returned - * in a response. - */ - // const displayLanguageCode = 'abc123' - /** - * Optional. Get supported languages of this model. - * The format depends on model type: - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * Returns languages supported by the specified model. - * If missing, we get supported languages of Google general NMT model. - */ - // const model = 'abc123' - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callGetSupportedLanguages() { - // Construct request - const request = { - parent, - }; - - // Run request - const response = await translationClient.getSupportedLanguages(request); - console.log(response); - } - - callGetSupportedLanguages(); - // [END translate_v3_generated_TranslationService_GetSupportedLanguages_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3/translation_service.list_glossaries.js b/samples/generated/v3/translation_service.list_glossaries.js deleted file mode 100644 index 2e5ed20b..00000000 --- a/samples/generated/v3/translation_service.list_glossaries.js +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent) { - // [START translate_v3_generated_TranslationService_ListGlossaries_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. The name of the project from which to list all of the glossaries. - */ - // const parent = 'abc123' - /** - * Optional. Requested page size. The server may return fewer glossaries than - * requested. If unspecified, the server picks an appropriate default. - */ - // const pageSize = 1234 - /** - * Optional. A token identifying a page of results the server should return. - * Typically, this is the value of ListGlossariesResponse.next_page_token - * returned from the previous call to `ListGlossaries` method. - * The first page is returned if `page_token`is empty or missing. - */ - // const pageToken = 'abc123' - /** - * Optional. Filter specifying constraints of a list operation. - * Specify the constraint by the format of "key=value", where key must be - * "src" or "tgt", and the value must be a valid language code. - * For multiple restrictions, concatenate them by "AND" (uppercase only), - * such as: "src=en-US AND tgt=zh-CN". Notice that the exact match is used - * here, which means using 'en-US' and 'en' can lead to different results, - * which depends on the language code you used when you create the glossary. - * For the unidirectional glossaries, the "src" and "tgt" add restrictions - * on the source and target language code separately. - * For the equivalent term set glossaries, the "src" and/or "tgt" add - * restrictions on the term set. - * For example: "src=en-US AND tgt=zh-CN" will only pick the unidirectional - * glossaries which exactly match the source language code as "en-US" and the - * target language code "zh-CN", but all equivalent term set glossaries which - * contain "en-US" and "zh-CN" in their language set will be picked. - * If missing, no filtering is performed. - */ - // const filter = 'abc123' - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callListGlossaries() { - // Construct request - const request = { - parent, - }; - - // Run request - const iterable = await translationClient.listGlossariesAsync(request); - for await (const response of iterable) { - console.log(response); - } - } - - callListGlossaries(); - // [END translate_v3_generated_TranslationService_ListGlossaries_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3/translation_service.translate_document.js b/samples/generated/v3/translation_service.translate_document.js deleted file mode 100644 index 069b2b60..00000000 --- a/samples/generated/v3/translation_service.translate_document.js +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent, targetLanguageCode, documentInputConfig) { - // [START translate_v3_generated_TranslationService_TranslateDocument_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. Location to make a regional call. - * Format: `projects/{project-number-or-id}/locations/{location-id}`. - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * Non-global location is required for requests using AutoML models or custom - * glossaries. - * Models and glossaries must be within the same region (have the same - * location-id), otherwise an INVALID_ARGUMENT (400) error is returned. - */ - // const parent = 'abc123' - /** - * Optional. The BCP-47 language code of the input document if known, for - * example, "en-US" or "sr-Latn". Supported language codes are listed in - * Language Support. If the source language isn't specified, the API attempts - * to identify the source language automatically and returns the source - * language within the response. Source language must be specified if the - * request contains a glossary or a custom model. - */ - // const sourceLanguageCode = 'abc123' - /** - * Required. The BCP-47 language code to use for translation of the input - * document, set to one of the language codes listed in Language Support. - */ - // const targetLanguageCode = 'abc123' - /** - * Required. Input configurations. - */ - // const documentInputConfig = {} - /** - * Optional. Output configurations. - * Defines if the output file should be stored within Cloud Storage as well - * as the desired output format. If not provided the translated file will - * only be returned through a byte-stream and its output mime type will be - * the same as the input file's mime type. - */ - // const documentOutputConfig = {} - /** - * Optional. The `model` type requested for this translation. - * The format depends on model type: - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * If not provided, the default Google model (NMT) will be used for - * translation. - */ - // const model = 'abc123' - /** - * Optional. Glossary to be applied. The glossary must be within the same - * region (have the same location-id) as the model, otherwise an - * INVALID_ARGUMENT (400) error is returned. - */ - // const glossaryConfig = {} - /** - * Optional. The labels with user-defined metadata for the request. - * Label keys and values can be no longer than 63 characters (Unicode - * codepoints), can only contain lowercase letters, numeric characters, - * underscores and dashes. International characters are allowed. Label values - * are optional. Label keys must start with a letter. - * See https://cloud.google.com/translate/docs/advanced/labels for more - * information. - */ - // const labels = 1234 - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callTranslateDocument() { - // Construct request - const request = { - parent, - targetLanguageCode, - documentInputConfig, - }; - - // Run request - const response = await translationClient.translateDocument(request); - console.log(response); - } - - callTranslateDocument(); - // [END translate_v3_generated_TranslationService_TranslateDocument_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3/translation_service.translate_text.js b/samples/generated/v3/translation_service.translate_text.js deleted file mode 100644 index 0eb65ba0..00000000 --- a/samples/generated/v3/translation_service.translate_text.js +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(contents, targetLanguageCode, parent) { - // [START translate_v3_generated_TranslationService_TranslateText_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. The content of the input in string format. - * We recommend the total content be less than 30k codepoints. The max length - * of this field is 1024. - * Use BatchTranslateText for larger text. - */ - // const contents = 'abc123' - /** - * Optional. The format of the source text, for example, "text/html", - * "text/plain". If left blank, the MIME type defaults to "text/html". - */ - // const mimeType = 'abc123' - /** - * Optional. The BCP-47 language code of the input text if - * known, for example, "en-US" or "sr-Latn". Supported language codes are - * listed in Language Support. If the source language isn't specified, the API - * attempts to identify the source language automatically and returns the - * source language within the response. - */ - // const sourceLanguageCode = 'abc123' - /** - * Required. The BCP-47 language code to use for translation of the input - * text, set to one of the language codes listed in Language Support. - */ - // const targetLanguageCode = 'abc123' - /** - * Required. Project or location to make a call. Must refer to a caller's - * project. - * Format: `projects/{project-number-or-id}` or - * `projects/{project-number-or-id}/locations/{location-id}`. - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * Non-global location is required for requests using AutoML models or - * custom glossaries. - * Models and glossaries must be within the same region (have same - * location-id), otherwise an INVALID_ARGUMENT (400) error is returned. - */ - // const parent = 'abc123' - /** - * Optional. The `model` type requested for this translation. - * The format depends on model type: - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * For global (non-regionalized) requests, use `location-id` `global`. - * For example, - * `projects/{project-number-or-id}/locations/global/models/general/nmt`. - * If not provided, the default Google model (NMT) will be used. - */ - // const model = 'abc123' - /** - * Optional. Glossary to be applied. The glossary must be - * within the same region (have the same location-id) as the model, otherwise - * an INVALID_ARGUMENT (400) error is returned. - */ - // const glossaryConfig = {} - /** - * Optional. The labels with user-defined metadata for the request. - * Label keys and values can be no longer than 63 characters - * (Unicode codepoints), can only contain lowercase letters, numeric - * characters, underscores and dashes. International characters are allowed. - * Label values are optional. Label keys must start with a letter. - * See https://cloud.google.com/translate/docs/advanced/labels for more - * information. - */ - // const labels = 1234 - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callTranslateText() { - // Construct request - const request = { - contents, - targetLanguageCode, - parent, - }; - - // Run request - const response = await translationClient.translateText(request); - console.log(response); - } - - callTranslateText(); - // [END translate_v3_generated_TranslationService_TranslateText_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3beta1/snippet_metadata.google.cloud.translation.v3beta1.json b/samples/generated/v3beta1/snippet_metadata.google.cloud.translation.v3beta1.json deleted file mode 100644 index 7a8f8743..00000000 --- a/samples/generated/v3beta1/snippet_metadata.google.cloud.translation.v3beta1.json +++ /dev/null @@ -1,567 +0,0 @@ -{ - "clientLibrary": { - "name": "nodejs-translation", - "version": "7.0.4", - "language": "TYPESCRIPT", - "apis": [ - { - "id": "google.cloud.translation.v3beta1", - "version": "v3beta1" - } - ] - }, - "snippets": [ - { - "regionTag": "translate_v3beta1_generated_TranslationService_TranslateText_async", - "title": "TranslationService translateText Sample", - "origin": "API_DEFINITION", - "description": " Translates input text and returns translated text.", - "canonical": true, - "file": "translation_service.translate_text.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 117, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "TranslateText", - "fullName": "google.cloud.translation.v3beta1.TranslationService.TranslateText", - "async": true, - "parameters": [ - { - "name": "contents", - "type": "TYPE_STRING[]" - }, - { - "name": "mime_type", - "type": "TYPE_STRING" - }, - { - "name": "source_language_code", - "type": "TYPE_STRING" - }, - { - "name": "target_language_code", - "type": "TYPE_STRING" - }, - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "model", - "type": "TYPE_STRING" - }, - { - "name": "glossary_config", - "type": ".google.cloud.translation.v3beta1.TranslateTextGlossaryConfig" - }, - { - "name": "labels", - "type": "TYPE_MESSAGE[]" - } - ], - "resultType": ".google.cloud.translation.v3beta1.TranslateTextResponse", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3beta1.TranslationServiceClient" - }, - "method": { - "shortName": "TranslateText", - "fullName": "google.cloud.translation.v3beta1.TranslationService.TranslateText", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3beta1.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3beta1_generated_TranslationService_DetectLanguage_async", - "title": "TranslationService detectLanguage Sample", - "origin": "API_DEFINITION", - "description": " Detects the language of text within a request.", - "canonical": true, - "file": "translation_service.detect_language.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 87, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "DetectLanguage", - "fullName": "google.cloud.translation.v3beta1.TranslationService.DetectLanguage", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "model", - "type": "TYPE_STRING" - }, - { - "name": "content", - "type": "TYPE_STRING" - }, - { - "name": "mime_type", - "type": "TYPE_STRING" - }, - { - "name": "labels", - "type": "TYPE_MESSAGE[]" - } - ], - "resultType": ".google.cloud.translation.v3beta1.DetectLanguageResponse", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3beta1.TranslationServiceClient" - }, - "method": { - "shortName": "DetectLanguage", - "fullName": "google.cloud.translation.v3beta1.TranslationService.DetectLanguage", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3beta1.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3beta1_generated_TranslationService_GetSupportedLanguages_async", - "title": "TranslationService getSupportedLanguages Sample", - "origin": "API_DEFINITION", - "description": " Returns a list of supported languages for translation.", - "canonical": true, - "file": "translation_service.get_supported_languages.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 78, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "GetSupportedLanguages", - "fullName": "google.cloud.translation.v3beta1.TranslationService.GetSupportedLanguages", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "display_language_code", - "type": "TYPE_STRING" - }, - { - "name": "model", - "type": "TYPE_STRING" - } - ], - "resultType": ".google.cloud.translation.v3beta1.SupportedLanguages", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3beta1.TranslationServiceClient" - }, - "method": { - "shortName": "GetSupportedLanguages", - "fullName": "google.cloud.translation.v3beta1.TranslationService.GetSupportedLanguages", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3beta1.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3beta1_generated_TranslationService_TranslateDocument_async", - "title": "TranslationService translateDocument Sample", - "origin": "API_DEFINITION", - "description": " Translates documents in synchronous mode.", - "canonical": true, - "file": "translation_service.translate_document.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 114, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "TranslateDocument", - "fullName": "google.cloud.translation.v3beta1.TranslationService.TranslateDocument", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "source_language_code", - "type": "TYPE_STRING" - }, - { - "name": "target_language_code", - "type": "TYPE_STRING" - }, - { - "name": "document_input_config", - "type": ".google.cloud.translation.v3beta1.DocumentInputConfig" - }, - { - "name": "document_output_config", - "type": ".google.cloud.translation.v3beta1.DocumentOutputConfig" - }, - { - "name": "model", - "type": "TYPE_STRING" - }, - { - "name": "glossary_config", - "type": ".google.cloud.translation.v3beta1.TranslateTextGlossaryConfig" - }, - { - "name": "labels", - "type": "TYPE_MESSAGE[]" - } - ], - "resultType": ".google.cloud.translation.v3beta1.TranslateDocumentResponse", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3beta1.TranslationServiceClient" - }, - "method": { - "shortName": "TranslateDocument", - "fullName": "google.cloud.translation.v3beta1.TranslationService.TranslateDocument", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3beta1.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3beta1_generated_TranslationService_BatchTranslateText_async", - "title": "TranslationService batchTranslateText Sample", - "origin": "API_DEFINITION", - "description": " Translates a large volume of text in asynchronous batch mode. This function provides real-time output as the inputs are being processed. If caller cancels a request, the partial results (for an input file, it's all or nothing) may still be available on the specified output location. This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call.", - "canonical": true, - "file": "translation_service.batch_translate_text.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 111, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "BatchTranslateText", - "fullName": "google.cloud.translation.v3beta1.TranslationService.BatchTranslateText", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "source_language_code", - "type": "TYPE_STRING" - }, - { - "name": "target_language_codes", - "type": "TYPE_STRING[]" - }, - { - "name": "models", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "input_configs", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "output_config", - "type": ".google.cloud.translation.v3beta1.OutputConfig" - }, - { - "name": "glossaries", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "labels", - "type": "TYPE_MESSAGE[]" - } - ], - "resultType": ".google.longrunning.Operation", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3beta1.TranslationServiceClient" - }, - "method": { - "shortName": "BatchTranslateText", - "fullName": "google.cloud.translation.v3beta1.TranslationService.BatchTranslateText", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3beta1.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3beta1_generated_TranslationService_BatchTranslateDocument_async", - "title": "TranslationService batchTranslateDocument Sample", - "origin": "API_DEFINITION", - "description": " Translates a large volume of documents in asynchronous batch mode. This function provides real-time output as the inputs are being processed. If caller cancels a request, the partial results (for an input file, it's all or nothing) may still be available on the specified output location. This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call.", - "canonical": true, - "file": "translation_service.batch_translate_document.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 115, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "BatchTranslateDocument", - "fullName": "google.cloud.translation.v3beta1.TranslationService.BatchTranslateDocument", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "source_language_code", - "type": "TYPE_STRING" - }, - { - "name": "target_language_codes", - "type": "TYPE_STRING[]" - }, - { - "name": "input_configs", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "output_config", - "type": ".google.cloud.translation.v3beta1.BatchDocumentOutputConfig" - }, - { - "name": "models", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "glossaries", - "type": "TYPE_MESSAGE[]" - }, - { - "name": "format_conversions", - "type": "TYPE_MESSAGE[]" - } - ], - "resultType": ".google.longrunning.Operation", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3beta1.TranslationServiceClient" - }, - "method": { - "shortName": "BatchTranslateDocument", - "fullName": "google.cloud.translation.v3beta1.TranslationService.BatchTranslateDocument", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3beta1.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3beta1_generated_TranslationService_CreateGlossary_async", - "title": "TranslationService createGlossary Sample", - "origin": "API_DEFINITION", - "description": " Creates a glossary and returns the long-running operation. Returns NOT_FOUND, if the project doesn't exist.", - "canonical": true, - "file": "translation_service.create_glossary.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 59, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "CreateGlossary", - "fullName": "google.cloud.translation.v3beta1.TranslationService.CreateGlossary", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "glossary", - "type": ".google.cloud.translation.v3beta1.Glossary" - } - ], - "resultType": ".google.longrunning.Operation", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3beta1.TranslationServiceClient" - }, - "method": { - "shortName": "CreateGlossary", - "fullName": "google.cloud.translation.v3beta1.TranslationService.CreateGlossary", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3beta1.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3beta1_generated_TranslationService_ListGlossaries_async", - "title": "TranslationService listGlossaries Sample", - "origin": "API_DEFINITION", - "description": " Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't exist.", - "canonical": true, - "file": "translation_service.list_glossaries.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 86, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "ListGlossaries", - "fullName": "google.cloud.translation.v3beta1.TranslationService.ListGlossaries", - "async": true, - "parameters": [ - { - "name": "parent", - "type": "TYPE_STRING" - }, - { - "name": "page_size", - "type": "TYPE_INT32" - }, - { - "name": "page_token", - "type": "TYPE_STRING" - }, - { - "name": "filter", - "type": "TYPE_STRING" - } - ], - "resultType": ".google.cloud.translation.v3beta1.ListGlossariesResponse", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3beta1.TranslationServiceClient" - }, - "method": { - "shortName": "ListGlossaries", - "fullName": "google.cloud.translation.v3beta1.TranslationService.ListGlossaries", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3beta1.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3beta1_generated_TranslationService_GetGlossary_async", - "title": "TranslationService getGlossary Sample", - "origin": "API_DEFINITION", - "description": " Gets a glossary. Returns NOT_FOUND, if the glossary doesn't exist.", - "canonical": true, - "file": "translation_service.get_glossary.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 53, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "GetGlossary", - "fullName": "google.cloud.translation.v3beta1.TranslationService.GetGlossary", - "async": true, - "parameters": [ - { - "name": "name", - "type": "TYPE_STRING" - } - ], - "resultType": ".google.cloud.translation.v3beta1.Glossary", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3beta1.TranslationServiceClient" - }, - "method": { - "shortName": "GetGlossary", - "fullName": "google.cloud.translation.v3beta1.TranslationService.GetGlossary", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3beta1.TranslationService" - } - } - } - }, - { - "regionTag": "translate_v3beta1_generated_TranslationService_DeleteGlossary_async", - "title": "TranslationService deleteGlossary Sample", - "origin": "API_DEFINITION", - "description": " Deletes a glossary, or cancels glossary construction if the glossary isn't created yet. Returns NOT_FOUND, if the glossary doesn't exist.", - "canonical": true, - "file": "translation_service.delete_glossary.js", - "language": "JAVASCRIPT", - "segments": [ - { - "start": 25, - "end": 54, - "type": "FULL" - } - ], - "clientMethod": { - "shortName": "DeleteGlossary", - "fullName": "google.cloud.translation.v3beta1.TranslationService.DeleteGlossary", - "async": true, - "parameters": [ - { - "name": "name", - "type": "TYPE_STRING" - } - ], - "resultType": ".google.longrunning.Operation", - "client": { - "shortName": "TranslationServiceClient", - "fullName": "google.cloud.translation.v3beta1.TranslationServiceClient" - }, - "method": { - "shortName": "DeleteGlossary", - "fullName": "google.cloud.translation.v3beta1.TranslationService.DeleteGlossary", - "service": { - "shortName": "TranslationService", - "fullName": "google.cloud.translation.v3beta1.TranslationService" - } - } - } - } - ] -} \ No newline at end of file diff --git a/samples/generated/v3beta1/translation_service.batch_translate_document.js b/samples/generated/v3beta1/translation_service.batch_translate_document.js deleted file mode 100644 index 5cea9cd7..00000000 --- a/samples/generated/v3beta1/translation_service.batch_translate_document.js +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) { - // [START translate_v3beta1_generated_TranslationService_BatchTranslateDocument_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. Location to make a regional call. - * Format: `projects/{project-number-or-id}/locations/{location-id}`. - * The `global` location is not supported for batch translation. - * Only AutoML Translation models or glossaries within the same region (have - * the same location-id) can be used, otherwise an INVALID_ARGUMENT (400) - * error is returned. - */ - // const parent = 'abc123' - /** - * Required. The BCP-47 language code of the input document if known, for - * example, "en-US" or "sr-Latn". Supported language codes are listed in - * Language Support (https://cloud.google.com/translate/docs/languages). - */ - // const sourceLanguageCode = 'abc123' - /** - * Required. The BCP-47 language code to use for translation of the input - * document. Specify up to 10 language codes here. - */ - // const targetLanguageCodes = 'abc123' - /** - * Required. Input configurations. - * The total number of files matched should be <= 100. - * The total content size to translate should be <= 100M Unicode codepoints. - * The files must use UTF-8 encoding. - */ - // const inputConfigs = 1234 - /** - * Required. Output configuration. - * If 2 input configs match to the same file (that is, same input path), - * we don't generate output for duplicate inputs. - */ - // const outputConfig = {} - /** - * Optional. The models to use for translation. Map's key is target language - * code. Map's value is the model name. Value can be a built-in general model, - * or an AutoML Translation model. - * The value format depends on model type: - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * If the map is empty or a specific model is not requested for a language - * pair, then default google model (nmt) is used. - */ - // const models = 1234 - /** - * Optional. Glossaries to be applied. It's keyed by target language code. - */ - // const glossaries = 1234 - /** - * Optional. File format conversion map to be applied to all input files. - * Map's key is the original mime_type. Map's value is the target mime_type of - * translated documents. - * Supported file format conversion includes: - * - `application/pdf` to - * `application/vnd.openxmlformats-officedocument.wordprocessingml.document` - * If nothing specified, output files will be in the same format as the - * original file. - */ - // const formatConversions = 1234 - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callBatchTranslateDocument() { - // Construct request - const request = { - parent, - sourceLanguageCode, - targetLanguageCodes, - inputConfigs, - outputConfig, - }; - - // Run request - const [operation] = await translationClient.batchTranslateDocument(request); - const [response] = await operation.promise(); - console.log(response); - } - - callBatchTranslateDocument(); - // [END translate_v3beta1_generated_TranslationService_BatchTranslateDocument_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3beta1/translation_service.batch_translate_text.js b/samples/generated/v3beta1/translation_service.batch_translate_text.js deleted file mode 100644 index 050b66c6..00000000 --- a/samples/generated/v3beta1/translation_service.batch_translate_text.js +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) { - // [START translate_v3beta1_generated_TranslationService_BatchTranslateText_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. Location to make a call. Must refer to a caller's project. - * Format: `projects/{project-number-or-id}/locations/{location-id}`. - * The `global` location is not supported for batch translation. - * Only AutoML Translation models or glossaries within the same region (have - * the same location-id) can be used, otherwise an INVALID_ARGUMENT (400) - * error is returned. - */ - // const parent = 'abc123' - /** - * Required. Source language code. - */ - // const sourceLanguageCode = 'abc123' - /** - * Required. Specify up to 10 language codes here. - */ - // const targetLanguageCodes = 'abc123' - /** - * Optional. The models to use for translation. Map's key is target language - * code. Map's value is model name. Value can be a built-in general model, - * or an AutoML Translation model. - * The value format depends on model type: - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * If the map is empty or a specific model is - * not requested for a language pair, then default google model (nmt) is used. - */ - // const models = 1234 - /** - * Required. Input configurations. - * The total number of files matched should be <= 100. - * The total content size should be <= 100M Unicode codepoints. - * The files must use UTF-8 encoding. - */ - // const inputConfigs = 1234 - /** - * Required. Output configuration. - * If 2 input configs match to the same file (that is, same input path), - * we don't generate output for duplicate inputs. - */ - // const outputConfig = {} - /** - * Optional. Glossaries to be applied for translation. - * It's keyed by target language code. - */ - // const glossaries = 1234 - /** - * Optional. The labels with user-defined metadata for the request. - * Label keys and values can be no longer than 63 characters - * (Unicode codepoints), can only contain lowercase letters, numeric - * characters, underscores and dashes. International characters are allowed. - * Label values are optional. Label keys must start with a letter. - * See https://cloud.google.com/translate/docs/labels for more information. - */ - // const labels = 1234 - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callBatchTranslateText() { - // Construct request - const request = { - parent, - sourceLanguageCode, - targetLanguageCodes, - inputConfigs, - outputConfig, - }; - - // Run request - const [operation] = await translationClient.batchTranslateText(request); - const [response] = await operation.promise(); - console.log(response); - } - - callBatchTranslateText(); - // [END translate_v3beta1_generated_TranslationService_BatchTranslateText_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3beta1/translation_service.create_glossary.js b/samples/generated/v3beta1/translation_service.create_glossary.js deleted file mode 100644 index c0282423..00000000 --- a/samples/generated/v3beta1/translation_service.create_glossary.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent, glossary) { - // [START translate_v3beta1_generated_TranslationService_CreateGlossary_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. The project name. - */ - // const parent = 'abc123' - /** - * Required. The glossary to create. - */ - // const glossary = {} - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callCreateGlossary() { - // Construct request - const request = { - parent, - glossary, - }; - - // Run request - const [operation] = await translationClient.createGlossary(request); - const [response] = await operation.promise(); - console.log(response); - } - - callCreateGlossary(); - // [END translate_v3beta1_generated_TranslationService_CreateGlossary_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3beta1/translation_service.delete_glossary.js b/samples/generated/v3beta1/translation_service.delete_glossary.js deleted file mode 100644 index a5f77fcf..00000000 --- a/samples/generated/v3beta1/translation_service.delete_glossary.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(name) { - // [START translate_v3beta1_generated_TranslationService_DeleteGlossary_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. The name of the glossary to delete. - */ - // const name = 'abc123' - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callDeleteGlossary() { - // Construct request - const request = { - name, - }; - - // Run request - const [operation] = await translationClient.deleteGlossary(request); - const [response] = await operation.promise(); - console.log(response); - } - - callDeleteGlossary(); - // [END translate_v3beta1_generated_TranslationService_DeleteGlossary_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3beta1/translation_service.detect_language.js b/samples/generated/v3beta1/translation_service.detect_language.js deleted file mode 100644 index cfd74d46..00000000 --- a/samples/generated/v3beta1/translation_service.detect_language.js +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent) { - // [START translate_v3beta1_generated_TranslationService_DetectLanguage_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. Project or location to make a call. Must refer to a caller's - * project. - * Format: `projects/{project-number-or-id}/locations/{location-id}` or - * `projects/{project-number-or-id}`. - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * Only models within the same region (has same location-id) can be used. - * Otherwise an INVALID_ARGUMENT (400) error is returned. - */ - // const parent = 'abc123' - /** - * Optional. The language detection model to be used. - * Format: - * `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/{model-id}` - * Only one language detection model is currently supported: - * `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/default`. - * If not specified, the default model is used. - */ - // const model = 'abc123' - /** - * The content of the input stored as a string. - */ - // const content = 'abc123' - /** - * Optional. The format of the source text, for example, "text/html", - * "text/plain". If left blank, the MIME type defaults to "text/html". - */ - // const mimeType = 'abc123' - /** - * Optional. The labels with user-defined metadata for the request. - * Label keys and values can be no longer than 63 characters - * (Unicode codepoints), can only contain lowercase letters, numeric - * characters, underscores and dashes. International characters are allowed. - * Label values are optional. Label keys must start with a letter. - * See https://cloud.google.com/translate/docs/labels for more information. - */ - // const labels = 1234 - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callDetectLanguage() { - // Construct request - const request = { - parent, - }; - - // Run request - const response = await translationClient.detectLanguage(request); - console.log(response); - } - - callDetectLanguage(); - // [END translate_v3beta1_generated_TranslationService_DetectLanguage_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3beta1/translation_service.get_glossary.js b/samples/generated/v3beta1/translation_service.get_glossary.js deleted file mode 100644 index 8f031109..00000000 --- a/samples/generated/v3beta1/translation_service.get_glossary.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(name) { - // [START translate_v3beta1_generated_TranslationService_GetGlossary_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. The name of the glossary to retrieve. - */ - // const name = 'abc123' - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callGetGlossary() { - // Construct request - const request = { - name, - }; - - // Run request - const response = await translationClient.getGlossary(request); - console.log(response); - } - - callGetGlossary(); - // [END translate_v3beta1_generated_TranslationService_GetGlossary_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3beta1/translation_service.get_supported_languages.js b/samples/generated/v3beta1/translation_service.get_supported_languages.js deleted file mode 100644 index 6d86e737..00000000 --- a/samples/generated/v3beta1/translation_service.get_supported_languages.js +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent) { - // [START translate_v3beta1_generated_TranslationService_GetSupportedLanguages_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. Project or location to make a call. Must refer to a caller's - * project. - * Format: `projects/{project-number-or-id}` or - * `projects/{project-number-or-id}/locations/{location-id}`. - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * Non-global location is required for AutoML models. - * Only models within the same region (have same location-id) can be used, - * otherwise an INVALID_ARGUMENT (400) error is returned. - */ - // const parent = 'abc123' - /** - * Optional. The language to use to return localized, human readable names - * of supported languages. If missing, then display names are not returned - * in a response. - */ - // const displayLanguageCode = 'abc123' - /** - * Optional. Get supported languages of this model. - * The format depends on model type: - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * Returns languages supported by the specified model. - * If missing, we get supported languages of Google general NMT model. - */ - // const model = 'abc123' - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callGetSupportedLanguages() { - // Construct request - const request = { - parent, - }; - - // Run request - const response = await translationClient.getSupportedLanguages(request); - console.log(response); - } - - callGetSupportedLanguages(); - // [END translate_v3beta1_generated_TranslationService_GetSupportedLanguages_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3beta1/translation_service.list_glossaries.js b/samples/generated/v3beta1/translation_service.list_glossaries.js deleted file mode 100644 index b6749dd2..00000000 --- a/samples/generated/v3beta1/translation_service.list_glossaries.js +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent) { - // [START translate_v3beta1_generated_TranslationService_ListGlossaries_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. The name of the project from which to list all of the glossaries. - */ - // const parent = 'abc123' - /** - * Optional. Requested page size. The server may return fewer glossaries than - * requested. If unspecified, the server picks an appropriate default. - */ - // const pageSize = 1234 - /** - * Optional. A token identifying a page of results the server should return. - * Typically, this is the value of ListGlossariesResponse.next_page_token - * returned from the previous call to `ListGlossaries` method. - * The first page is returned if `page_token`is empty or missing. - */ - // const pageToken = 'abc123' - /** - * Optional. Filter specifying constraints of a list operation. - * Specify the constraint by the format of "key=value", where key must be - * "src" or "tgt", and the value must be a valid language code. - * For multiple restrictions, concatenate them by "AND" (uppercase only), - * such as: "src=en-US AND tgt=zh-CN". Notice that the exact match is used - * here, which means using 'en-US' and 'en' can lead to different results, - * which depends on the language code you used when you create the glossary. - * For the unidirectional glossaries, the "src" and "tgt" add restrictions - * on the source and target language code separately. - * For the equivalent term set glossaries, the "src" and/or "tgt" add - * restrictions on the term set. - * For example: "src=en-US AND tgt=zh-CN" will only pick the unidirectional - * glossaries which exactly match the source language code as "en-US" and the - * target language code "zh-CN", but all equivalent term set glossaries which - * contain "en-US" and "zh-CN" in their language set will be picked. - * If missing, no filtering is performed. - */ - // const filter = 'abc123' - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callListGlossaries() { - // Construct request - const request = { - parent, - }; - - // Run request - const iterable = await translationClient.listGlossariesAsync(request); - for await (const response of iterable) { - console.log(response); - } - } - - callListGlossaries(); - // [END translate_v3beta1_generated_TranslationService_ListGlossaries_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3beta1/translation_service.translate_document.js b/samples/generated/v3beta1/translation_service.translate_document.js deleted file mode 100644 index ba5432f9..00000000 --- a/samples/generated/v3beta1/translation_service.translate_document.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(parent, targetLanguageCode, documentInputConfig) { - // [START translate_v3beta1_generated_TranslationService_TranslateDocument_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. Location to make a regional call. - * Format: `projects/{project-number-or-id}/locations/{location-id}`. - * For global calls, use `projects/{project-number-or-id}/locations/global`. - * Non-global location is required for requests using AutoML models or custom - * glossaries. - * Models and glossaries must be within the same region (have the same - * location-id), otherwise an INVALID_ARGUMENT (400) error is returned. - */ - // const parent = 'abc123' - /** - * Optional. The BCP-47 language code of the input document if known, for - * example, "en-US" or "sr-Latn". Supported language codes are listed in - * Language Support. If the source language isn't specified, the API attempts - * to identify the source language automatically and returns the source - * language within the response. Source language must be specified if the - * request contains a glossary or a custom model. - */ - // const sourceLanguageCode = 'abc123' - /** - * Required. The BCP-47 language code to use for translation of the input - * document, set to one of the language codes listed in Language Support. - */ - // const targetLanguageCode = 'abc123' - /** - * Required. Input configurations. - */ - // const documentInputConfig = {} - /** - * Optional. Output configurations. - * Defines if the output file should be stored within Cloud Storage as well - * as the desired output format. If not provided the translated file will - * only be returned through a byte-stream and its output mime type will be - * the same as the input file's mime type. - */ - // const documentOutputConfig = {} - /** - * Optional. The `model` type requested for this translation. - * The format depends on model type: - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * If not provided, the default Google model (NMT) will be used for - * translation. - */ - // const model = 'abc123' - /** - * Optional. Glossary to be applied. The glossary must be within the same - * region (have the same location-id) as the model, otherwise an - * INVALID_ARGUMENT (400) error is returned. - */ - // const glossaryConfig = {} - /** - * Optional. The labels with user-defined metadata for the request. - * Label keys and values can be no longer than 63 characters (Unicode - * codepoints), can only contain lowercase letters, numeric characters, - * underscores and dashes. International characters are allowed. Label values - * are optional. Label keys must start with a letter. - * See https://cloud.google.com/translate/docs/advanced/labels for more - * information. - */ - // const labels = 1234 - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callTranslateDocument() { - // Construct request - const request = { - parent, - targetLanguageCode, - documentInputConfig, - }; - - // Run request - const response = await translationClient.translateDocument(request); - console.log(response); - } - - callTranslateDocument(); - // [END translate_v3beta1_generated_TranslationService_TranslateDocument_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/generated/v3beta1/translation_service.translate_text.js b/samples/generated/v3beta1/translation_service.translate_text.js deleted file mode 100644 index bb98ef28..00000000 --- a/samples/generated/v3beta1/translation_service.translate_text.js +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - - -'use strict'; - -function main(contents, targetLanguageCode, parent) { - // [START translate_v3beta1_generated_TranslationService_TranslateText_async] - /** - * This snippet has been automatically generated and should be regarded as a code template only. - * It will require modifications to work. - * It may require correct/in-range values for request initialization. - * TODO(developer): Uncomment these variables before running the sample. - */ - /** - * Required. The content of the input in string format. - * We recommend the total content be less than 30k codepoints. The max length - * of this field is 1024. - * Use BatchTranslateText for larger text. - */ - // const contents = 'abc123' - /** - * Optional. The format of the source text, for example, "text/html", - * "text/plain". If left blank, the MIME type defaults to "text/html". - */ - // const mimeType = 'abc123' - /** - * Optional. The BCP-47 language code of the input text if - * known, for example, "en-US" or "sr-Latn". Supported language codes are - * listed in Language Support. If the source language isn't specified, the API - * attempts to identify the source language automatically and returns the - * source language within the response. - */ - // const sourceLanguageCode = 'abc123' - /** - * Required. The BCP-47 language code to use for translation of the input - * text, set to one of the language codes listed in Language Support. - */ - // const targetLanguageCode = 'abc123' - /** - * Required. Project or location to make a call. Must refer to a caller's - * project. - * Format: `projects/{project-number-or-id}` or - * `projects/{project-number-or-id}/locations/{location-id}`. - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * Non-global location is required for requests using AutoML models or - * custom glossaries. - * Models and glossaries must be within the same region (have same - * location-id), otherwise an INVALID_ARGUMENT (400) error is returned. - */ - // const parent = 'abc123' - /** - * Optional. The `model` type requested for this translation. - * The format depends on model type: - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * For global (non-regionalized) requests, use `location-id` `global`. - * For example, - * `projects/{project-number-or-id}/locations/global/models/general/nmt`. - * If not provided, the default Google model (NMT) will be used - */ - // const model = 'abc123' - /** - * Optional. Glossary to be applied. The glossary must be - * within the same region (have the same location-id) as the model, otherwise - * an INVALID_ARGUMENT (400) error is returned. - */ - // const glossaryConfig = {} - /** - * Optional. The labels with user-defined metadata for the request. - * Label keys and values can be no longer than 63 characters - * (Unicode codepoints), can only contain lowercase letters, numeric - * characters, underscores and dashes. International characters are allowed. - * Label values are optional. Label keys must start with a letter. - * See https://cloud.google.com/translate/docs/labels for more information. - */ - // const labels = 1234 - - // Imports the Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function callTranslateText() { - // Construct request - const request = { - contents, - targetLanguageCode, - parent, - }; - - // Run request - const response = await translationClient.translateText(request); - console.log(response); - } - - callTranslateText(); - // [END translate_v3beta1_generated_TranslationService_TranslateText_async] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/hybridGlossaries.js b/samples/hybridGlossaries.js deleted file mode 100644 index c800b0fc..00000000 --- a/samples/hybridGlossaries.js +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -async function main( - projectId = process.env.GCLOUD_PROJECT, // Your GCP Project Id - inFile = 'resources/example.png', - outFile = 'resources/example.mp3', - glossaryLangs = ['fr', 'en'], - glossaryName = 'bistro-glossary', - glossaryUri = 'gs://cloud-samples-data/translation/bistro_glossary.csv' -) { - // [START translate_hybrid_imports] - // Imports the Google Cloud client library - const textToSpeech = require('@google-cloud/text-to-speech'); - const translate = require('@google-cloud/translate').v3beta1; - const vision = require('@google-cloud/vision'); - - // Import other required libraries - const fs = require('fs'); - //const escape = require('escape-html'); - const util = require('util'); - // [END translate_hybrid_imports] - - // [START translate_hybrid_vision] - /** - * Detects text in an image file - * - * ARGS - * inputFile: path to image file - * RETURNS - * string of text detected in the input image - **/ - async function picToText(inputFile) { - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - // Performs text detection on the local file - const [result] = await client.textDetection(inputFile); - return result.fullTextAnnotation.text; - } - // [END translate_hybrid_vision] - - // [START translate_hybrid_create_glossary] - /** Creates a GCP glossary resource - * Assumes you've already manually uploaded a glossary to Cloud Storage - * - * ARGS - * languages: list of languages in the glossary - * projectId: GCP project id - * glossaryName: name you want to give this glossary resource - * glossaryUri: the uri of the glossary you uploaded to Cloud Storage - * RETURNS - * nothing - **/ - async function createGlossary( - languages, - projectId, - glossaryName, - glossaryUri - ) { - // Instantiates a client - const translationClient = await new translate.TranslationServiceClient(); - - // Construct glossary - const glossary = { - languageCodesSet: { - languageCodes: languages, - }, - inputConfig: { - gcsSource: { - inputUri: glossaryUri, - }, - }, - name: translationClient.glossaryPath( - projectId, - 'us-central1', - glossaryName - ), - }; - - // Construct request - const request = { - parent: translationClient.locationPath(projectId, 'us-central1'), - glossary: glossary, - }; - - // Create glossary using a long-running operation. - try { - const [operation] = await translationClient.createGlossary(request); - // Wait for operation to complete. - await operation.promise(); - console.log('Created glossary ' + glossaryName + '.'); - } catch (AlreadyExists) { - console.log( - 'The glossary ' + - glossaryName + - ' already exists. No new glossary was created.' - ); - } - } - // [END translate_hybrid_create_glossary] - - // [START translate_hybrid_translate] - /** - * Translates text to a given language using a glossary - * - * ARGS - * text: String of text to translate - * sourceLanguageCode: language of input text - * targetLanguageCode: language of output text - * projectId: GCP project id - * glossaryName: name you gave your project's glossary - * resource when you created it - * RETURNS - * String of translated text - **/ - async function translateText( - text, - sourceLanguageCode, - targetLanguageCode, - projectId, - glossaryName - ) { - // Instantiates a client - const translationClient = new translate.TranslationServiceClient(); - const glossary = translationClient.glossaryPath( - projectId, - 'us-central1', - glossaryName - ); - const glossaryConfig = { - glossary: glossary, - }; - // Construct request - const request = { - parent: translationClient.locationPath(projectId, 'us-central1'), - contents: [text], - mimeType: 'text/plain', // mime types: text/plain, text/html - sourceLanguageCode: sourceLanguageCode, - targetLanguageCode: targetLanguageCode, - glossaryConfig: glossaryConfig, - }; - - // Run request - const [response] = await translationClient.translateText(request); - // Extract the string of translated text - return response.glossaryTranslations[0].translatedText; - } - // [END translate_hybrid_translate] - - // [START translate_hybrid_tts] - /** - * Generates synthetic audio from plaintext tagged with SSML. - * - * Given the name of a text file and an output file name, this function - * tags the text in the text file with SSML. This function then - * calls the Text-to-Speech API. The API returns a synthetic audio - * version of the text, formatted according to the SSML commands. This - * function saves the synthetic audio to the designated output file. - * - * ARGS - * text: String of plaintext - * outFile: String name of file under which to save audio output - * RETURNS - * nothing - * - */ - async function syntheticAudio(text, outFile) { - // Replace special characters with HTML Ampersand Character Codes - // These codes prevent the API from confusing text with SSML tags - // For example, '<' --> '<' and '&' --> '&' - let escapedLines = text.replace(/&/g, '&'); - escapedLines = escapedLines.replace(/"/g, '"'); - escapedLines = escapedLines.replace(//g, '>'); - - // Convert plaintext to SSML - // Tag SSML so that there is a 2 second pause between each address - const expandedNewline = escapedLines.replace(/\n/g, '\n'); - const ssmlText = '' + expandedNewline + ''; - - // Creates a client - const client = new textToSpeech.TextToSpeechClient(); - - // Constructs the request - const request = { - // Select the text to synthesize - input: {ssml: ssmlText}, - // Select the language and SSML Voice Gender (optional) - voice: {languageCode: 'en-US', ssmlGender: 'MALE'}, - // Select the type of audio encoding - audioConfig: {audioEncoding: 'MP3'}, - }; - - // Performs the Text-to-Speech request - const [response] = await client.synthesizeSpeech(request); - // Write the binary audio content to a local file - const writeFile = util.promisify(fs.writeFile); - await writeFile(outFile, response.audioContent, 'binary'); - console.log('Audio content written to file ' + outFile); - } - // [END translate_hybrid_tts] - - // [START translate_hybrid_integration] - await createGlossary(glossaryLangs, projectId, glossaryName, glossaryUri); - const text = await picToText(inFile); - const translatedText = await translateText( - text, - 'fr', - 'en', - projectId, - glossaryName - ); - syntheticAudio(translatedText, outFile); - // [END translate_hybrid_integration] -} - -main(...process.argv.slice(2)); diff --git a/samples/package.json b/samples/package.json deleted file mode 100644 index a00a6cfe..00000000 --- a/samples/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "nodejs-docs-samples-translate", - "private": true, - "license": "Apache-2.0", - "author": "Google Inc.", - "repository": "googleapis/nodejs-translate", - "files": [ - "!test/" - ], - "engines": { - "node": ">=12.0.0" - }, - "scripts": { - "test": "mocha --recursive --timeout 240000" - }, - "dependencies": { - "@google-cloud/automl": "^3.0.0", - "@google-cloud/text-to-speech": "^4.0.0", - "@google-cloud/translate": "^7.0.4", - "@google-cloud/vision": "^3.0.0", - "yargs": "^16.0.0" - }, - "devDependencies": { - "@google-cloud/storage": "^6.0.0", - "chai": "^4.2.0", - "mocha": "^8.0.0", - "uuid": "^9.0.0" - } -} diff --git a/samples/quickstart.js b/samples/quickstart.js deleted file mode 100644 index 57bc3254..00000000 --- a/samples/quickstart.js +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID' // Your GCP Project Id -) { - // [START translate_quickstart] - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - - // Imports the Google Cloud client library - const {Translate} = require('@google-cloud/translate').v2; - - // Instantiates a client - const translate = new Translate({projectId}); - - async function quickStart() { - // The text to translate - const text = 'Hello, world!'; - - // The target language - const target = 'ru'; - - // Translates some text into Russian - const [translation] = await translate.translate(text, target); - console.log(`Text: ${text}`); - console.log(`Translation: ${translation}`); - } - - quickStart(); - // [END translate_quickstart] -} - -main(...process.argv.slice(2)); diff --git a/samples/resources/example.png b/samples/resources/example.png deleted file mode 100644 index a3ac25ab..00000000 Binary files a/samples/resources/example.png and /dev/null differ diff --git a/samples/test/hybridGlossaries.test.js b/samples/test/hybridGlossaries.test.js deleted file mode 100644 index f8861c4d..00000000 --- a/samples/test/hybridGlossaries.test.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const fs = require('fs'); -const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_hybrid_glossaries'; - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const glossaryId = 'bistro-glossary'; - const outputFile = 'resources/example.mp3'; - - before(() => { - try { - fs.unlinkSync(outputFile); - } catch (e) { - // don't throw an exception - } - }); - - it('should create a glossary', async () => { - const projectId = await translationClient.getProjectId(); - const output = execSync(`node hybridGlossaries.js ${projectId}`); - assert(output.includes(glossaryId)); - assert.strictEqual(fs.existsSync(outputFile), true); - }); - - after(async () => { - fs.unlinkSync(outputFile); - assert.strictEqual(fs.existsSync(outputFile), false); - // get projectId - const projectId = await translationClient.getProjectId(); - const name = translationClient.glossaryPath( - projectId, - location, - glossaryId - ); - const request = { - parent: translationClient.locationPath(projectId, location), - name: name, - }; - - // Delete glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.deleteGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - }); -}); diff --git a/samples/test/quickstart.test.js b/samples/test/quickstart.test.js deleted file mode 100644 index f1ed0c72..00000000 --- a/samples/test/quickstart.test.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2017 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); -const path = require('path'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const cwd = path.join(__dirname, '..'); -const projectId = process.env.GCLOUD_PROJECT; - -describe('quickstart sample tests', () => { - it('should translate a string', async () => { - const stdout = execSync(`node quickstart ${projectId}`, {cwd}); - assert.include(stdout, 'Translation: Привет'); - }); -}); diff --git a/samples/test/translate.test.js b/samples/test/translate.test.js deleted file mode 100644 index 0124c2fb..00000000 --- a/samples/test/translate.test.js +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2017 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {Translate} = require('@google-cloud/translate').v2; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}).trim(); -const translate = new Translate(); -const cmd = 'node translate.js'; -const text = 'Hello world!'; -const text2 = 'Goodbye!'; -const model = 'nmt'; -const toLang = 'ru'; - -describe('translate sample tests', () => { - it('should detect language of a single string', async () => { - const output = execSync(`${cmd} detect "${text}"`); - const [detection] = await translate.detect(text); - const expected = new RegExp( - `Detections:\n${text} => ${detection.language}` - ); - assert.match(output, expected); - }); - - it('should detect language of multiple strings', async () => { - const output = execSync(`${cmd} detect "${text}" "${text2}"`); - const [detections] = await translate.detect([text, text2]); - const expected = new RegExp( - `Detections:\n${text} => ${detections[0].language}\n${text2} => ${detections[1].language}` - ); - assert.match(output, expected); - }); - - it('should list languages', () => { - const output = execSync(`${cmd} list`); - assert.match(output, /Languages:/); - assert.match(output, new RegExp("{ code: 'af', name: 'Afrikaans' }")); - }); - - it('should list languages with a target', () => { - const output = execSync(`${cmd} list es`); - assert.match(output, /Languages:/); - assert.match(output, new RegExp("{ code: 'af', name: 'afrikáans' }")); - }); - - it('should translate a single string', async () => { - const output = execSync(`${cmd} translate ${toLang} "${text}"`); - const [translation] = await translate.translate(text, toLang); - const expected = `Translations:\n${text} => (${toLang}) ${translation}`; - assert.strictEqual(output, expected); - }); - - it('should translate multiple strings', async () => { - const output = execSync(`${cmd} translate ${toLang} "${text}" "${text2}"`); - const [translations] = await translate.translate([text, text2], toLang); - const expected = `Translations:\n${text} => (${toLang}) ${translations[0]}\n${text2} => (${toLang}) ${translations[1]}`; - assert.strictEqual(output, expected); - }); - - it('should translate a single string with a model', async () => { - const output = execSync( - `${cmd} translate-with-model ${toLang} ${model} "${text}"` - ); - const [translation] = await translate.translate(text, toLang); - const expected = `Translations:\n${text} => (${toLang}) ${translation}`; - assert.strictEqual(output, expected); - }); - - it('should translate multiple strings with a model', async () => { - const output = execSync( - `${cmd} translate-with-model ${toLang} ${model} "${text}" "${text2}"` - ); - const [translations] = await translate.translate([text, text2], toLang); - const expected = `Translations:\n${text} => (${toLang}) ${translations[0]}\n${text2} => (${toLang}) ${translations[1]}`; - assert.strictEqual(output, expected); - }); -}); diff --git a/samples/test/v3/translate_batch_translate_text.test.js b/samples/test/v3/translate_batch_translate_text.test.js deleted file mode 100644 index 846b3658..00000000 --- a/samples/test/v3/translate_batch_translate_text.test.js +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const {Storage} = require('@google-cloud/storage'); -const cp = require('child_process'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_batch_translate_text'; - -async function clearBucket(projectId, storage, bucketUuid) { - const options = { - prefix: `translation-${bucketUuid}/BATCH_TRANSLATE_OUTPUT/`, - delimeter: '/', - }; - - const bucket = await storage.bucket(projectId); - const [files] = await bucket.getFiles(options); - const length = files.length; - if (length > 0) { - await Promise.all(files.map(file => file.delete())); - } -} - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const bucketUuid = uuid.v4(); - const bucketName = `translation-${bucketUuid}/BATCH_TRANSLATE_OUTPUT/`; - const storage = new Storage(); - - before(async () => { - const projectId = await translationClient.getProjectId(); - - //Create bucket if needed - await storage - .createBucket(projectId, { - location: 'US', - storageClass: 'COLDLINE', - }) - .catch(error => { - if (error.code !== 409) { - //if it's not a duplicate bucket error, let the user know - console.error(error); - } - }); - }), - it('should batch translate the input text', async function () { - this.retries(3); - const projectId = await translationClient.getProjectId(); - await clearBucket(projectId, storage, bucketUuid); - const inputUri = 'gs://cloud-samples-data/translation/text.txt'; - - const outputUri = `gs://${projectId}/${bucketName}`; - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${inputUri} ${outputUri}` - ); - assert.match(output, /Total Characters: 13/); - assert.match(output, /Translated Characters: 13/); - }), - // Delete the folder from GCS for cleanup - after(async () => { - const projectId = await translationClient.getProjectId(); - const options = { - prefix: `translation-${bucketUuid}`, - }; - - const bucket = await storage.bucket(projectId); - const [files] = await bucket.getFiles(options); - const length = files.length; - if (length > 0) { - await Promise.all(files.map(file => file.delete())); - } - }); -}); diff --git a/samples/test/v3/translate_batch_translate_text_with_glossary.test.js b/samples/test/v3/translate_batch_translate_text_with_glossary.test.js deleted file mode 100644 index 2e38b852..00000000 --- a/samples/test/v3/translate_batch_translate_text_with_glossary.test.js +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const {Storage} = require('@google-cloud/storage'); -const cp = require('child_process'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const GLOSSARY_ID = 'DO_NET_DELETE_TEST_GLOSSARY_ES'; -const REGION_TAG = 'translate_batch_translate_text_with_glossary'; - -async function clearBucket(projectId, storage, bucketUuid) { - const options = { - prefix: `translation-${bucketUuid}/BATCH_TRANSLATE_WITH_GLOS_OUTPUT/`, - delimeter: '/', - }; - - const bucket = await storage.bucket(projectId); - const [files] = await bucket.getFiles(options); - const length = files.length; - if (length > 0) { - await Promise.all(files.map(file => file.delete())); - } -} - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const bucketUuid = uuid.v4(); - const bucketName = `translation-${bucketUuid}/BATCH_TRANSLATE_WITH_GLOS_OUTPUT/`; - const storage = new Storage(); - - before(async () => { - const projectId = await translationClient.getProjectId(); - - //Create bucket if needed - await storage - .createBucket(projectId, { - location: 'US', - storageClass: 'COLDLINE', - }) - .catch(error => { - if (error.code !== 409) { - //if it's not a duplicate bucket error, let the user know - console.error(error); - } - }); - }); - - it('should batch translate the input text with a glossary', async function () { - this.retries(3); - const projectId = await translationClient.getProjectId(); - // make sure the bucket is empty. - await clearBucket(projectId, storage, bucketUuid); - const inputUri = 'gs://cloud-samples-data/translation/text.txt'; - - const outputUri = `gs://${projectId}/${bucketName}`; - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${inputUri} ${outputUri} ${GLOSSARY_ID}` - ); - assert.match(output, /Total Characters: 13/); - assert.match(output, /Translated Characters: 13/); - }); - - // Delete the folder from GCS for cleanup - after(async () => { - const projectId = await translationClient.getProjectId(); - const options = { - prefix: `translation-${bucketUuid}`, - }; - - const bucket = await storage.bucket(projectId); - const [files] = await bucket.getFiles(options); - const length = files.length; - if (length > 0) { - await Promise.all(files.map(file => file.delete())); - } - }); -}); diff --git a/samples/test/v3/translate_batch_translate_text_with_glossary_and_model.test.js b/samples/test/v3/translate_batch_translate_text_with_glossary_and_model.test.js deleted file mode 100644 index 4a119696..00000000 --- a/samples/test/v3/translate_batch_translate_text_with_glossary_and_model.test.js +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const {Storage} = require('@google-cloud/storage'); -const cp = require('child_process'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const GLOSSARY_ID = 'DO_NOT_DELETE_TEST_GLOSSARY'; -const REGION_TAG = 'translate_batch_translate_text_with_glossary_and_model'; - -async function clearBucket(projectId, storage, bucketUuid) { - const options = { - prefix: `translation-${bucketUuid}/BATCH_TRANSLATE_GLOSS_MODEL_OUTPUT/`, - delimeter: '/', - }; - - const bucket = await storage.bucket(projectId); - const [files] = await bucket.getFiles(options); - const length = files.length; - if (length > 0) { - await Promise.all(files.map(file => file.delete())); - } -} - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const modelId = 'TRL8567014172607381504'; - const bucketUuid = uuid.v4(); - const bucketName = `translation-${bucketUuid}/BATCH_TRANSLATE_GLOSS_MODEL_OUTPUT/`; - const storage = new Storage(); - - before(async () => { - const projectId = await translationClient.getProjectId(); - - //Create bucket if needed - await storage - .createBucket(projectId, { - location: 'US', - storageClass: 'COLDLINE', - }) - .catch(error => { - if (error.code !== 409) { - //if it's not a duplicate bucket error, let the user know - console.error(error); - } - }); - }); - - it('should batch translate the input text with a glossary', async function () { - this.retries(3); - const projectId = await translationClient.getProjectId(); - await clearBucket(projectId, storage, bucketUuid); - const inputUri = - 'gs://cloud-samples-data/translation/text_with_custom_model_and_glossary.txt'; - - const outputUri = `gs://${projectId}/${bucketName}`; - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${inputUri} ${outputUri} ${GLOSSARY_ID} ${modelId}` - ); - assert.match(output, /Total Characters/); - assert.match(output, /Translated Characters/); - - // batch translate fluctuates between 2 to 4 minutes. - this.timeout(300000); - }); - - // Delete the folder from GCS for cleanup - after(async () => { - const projectId = await translationClient.getProjectId(); - const options = { - prefix: `translation-${bucketUuid}`, - }; - - const bucket = await storage.bucket(projectId); - const [files] = await bucket.getFiles(options); - const length = files.length; - if (length > 0) { - await Promise.all(files.map(file => file.delete())); - } - }); -}); diff --git a/samples/test/v3/translate_batch_translate_text_with_model.test.js b/samples/test/v3/translate_batch_translate_text_with_model.test.js deleted file mode 100644 index e6715dce..00000000 --- a/samples/test/v3/translate_batch_translate_text_with_model.test.js +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, before, afterEach} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const {Storage} = require('@google-cloud/storage'); -const cp = require('child_process'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_batch_translate_text_with_model'; - -async function clearBucket(projectId, storage, bucketUuid) { - const options = { - prefix: `translation-${bucketUuid}/BATCH_TRANSLATE_WITH_MODEL_OUTPUT/`, - delimeter: '/', - }; - - const bucket = await storage.bucket(projectId); - const [files] = await bucket.getFiles(options); - const length = files.length; - if (length > 0) { - await Promise.all(files.map(file => file.delete())); - } -} - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const modelId = 'TRL8567014172607381504'; - const bucketUuid = uuid.v4(); - const bucketName = `translation-${bucketUuid}/BATCH_TRANSLATE_WITH_MODEL_OUTPUT/`; - const storage = new Storage(); - - before(async () => { - const projectId = await translationClient.getProjectId(); - - //Create bucket if needed - await storage - .createBucket(projectId, { - location: 'US', - storageClass: 'COLDLINE', - }) - .catch(error => { - if (error.code !== 409) { - //if it's not a duplicate bucket error, let the user know - console.error(error); - } - }); - }); - - it('should batch translate the input text with a model', async function () { - this.retries(3); - const projectId = await translationClient.getProjectId(); - await clearBucket(projectId, storage, bucketUuid); - const inputUri = - 'gs://cloud-samples-data/translation/custom_model_text.txt'; - - const outputUri = `gs://${projectId}/${bucketName}`; - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${inputUri} ${outputUri} ${modelId}` - ); - assert.match(output, /Total Characters/); - assert.match(output, /Translated Characters/); - }); - - // Delete the folder from GCS for cleanup - afterEach(async () => { - const projectId = await translationClient.getProjectId(); - const options = { - prefix: `translation-${bucketUuid}`, - }; - - const bucket = await storage.bucket(projectId); - const [files] = await bucket.getFiles(options); - const length = files.length; - if (length > 0) { - await Promise.all(files.map(file => file.delete())); - } - }); -}); diff --git a/samples/test/v3/translate_create_glossary.test.js b/samples/test/v3/translate_create_glossary.test.js deleted file mode 100644 index c708de74..00000000 --- a/samples/test/v3/translate_create_glossary.test.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, after} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_create_glossary'; - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const glossaryId = `my_test_glossary_${uuid.v4()}`; - const location = 'us-central1'; - - it('should create a glossary', async () => { - const projectId = await translationClient.getProjectId(); - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${glossaryId}` - ); - assert.match( - output, - /gs:\/\/cloud-samples-data\/translation\/glossary.csv/ - ); - }); - - after('cleanup for glossary create', async () => { - const projectId = await translationClient.getProjectId(); - // Delete the glossary to clean up - const request = { - parent: `projects/${projectId}/locations/${location}`, - name: `projects/${projectId}/locations/${location}/glossaries/${glossaryId}`, - }; - - // Delete glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.deleteGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - }); -}); diff --git a/samples/test/v3/translate_delete_glossary.test.js b/samples/test/v3/translate_delete_glossary.test.js deleted file mode 100644 index 0a4b0450..00000000 --- a/samples/test/v3/translate_delete_glossary.test.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, before} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_delete_glossary'; - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const glossaryId = `my_test_glossary_${uuid.v4()}`; - - before(async () => { - // Add a glossary to be deleted - // const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const glossary = { - languageCodesSet: { - languageCodes: ['en', 'es'], - }, - inputConfig: { - gcsSource: { - inputUri: 'gs://cloud-samples-data/translation/glossary.csv', - }, - }, - name: `projects/${projectId}/locations/${location}/glossaries/${glossaryId}`, - }; - - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - glossary: glossary, - }; - - // Create glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.createGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - }); - - it('should delete a glossary', async () => { - const projectId = await translationClient.getProjectId(); - - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${glossaryId}` - ); - assert.match(output, /glossary/); - }); -}); diff --git a/samples/test/v3/translate_detect_language.test.js b/samples/test/v3/translate_detect_language.test.js deleted file mode 100644 index ae0743e9..00000000 --- a/samples/test/v3/translate_detect_language.test.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_detect_language'; - -describe(REGION_TAG, () => { - it('should detect the language of the input text', async () => { - const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const location = 'global'; - const text = "'Hæ sæta'"; - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${text}` - ); - assert.match(output, /Language Code: is/); - assert.match(output, /Confidence: 1/); - }); -}); diff --git a/samples/test/v3/translate_get_glossary.test.js b/samples/test/v3/translate_get_glossary.test.js deleted file mode 100644 index 41dcf9e5..00000000 --- a/samples/test/v3/translate_get_glossary.test.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const GLOSSARY_ID = 'DO_NOT_DELETE_TEST_GLOSSARY'; -const REGION_TAG = 'translate_get_glossary'; - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - - it('should get a glossary', async () => { - const projectId = await translationClient.getProjectId(); - - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${GLOSSARY_ID}` - ); - assert.match(output, /DO_NOT_DELETE_TEST_GLOSSARY/); - }); -}); diff --git a/samples/test/v3/translate_get_supported_languages.test.js b/samples/test/v3/translate_get_supported_languages.test.js deleted file mode 100644 index d9806577..00000000 --- a/samples/test/v3/translate_get_supported_languages.test.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_get_supported_languages'; - -describe(REGION_TAG, () => { - it('should get supported langauges', async () => { - const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const output = execSync(`node v3/${REGION_TAG}.js ${projectId}`); - assert.match(output, /zh/); - }); -}); diff --git a/samples/test/v3/translate_get_supported_languages_for_targets.test.js b/samples/test/v3/translate_get_supported_languages_for_targets.test.js deleted file mode 100644 index de3c5b62..00000000 --- a/samples/test/v3/translate_get_supported_languages_for_targets.test.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_get_supported_languages_for_target'; - -describe(REGION_TAG, () => { - it('should get supported langauges for target', async () => { - const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const output = execSync(`node v3/${REGION_TAG}.js ${projectId}`); - assert.match(output, /Language Code: yi/); - assert.match(output, /Display Name: Yiddish/); - }); -}); diff --git a/samples/test/v3/translate_list_codes.test.js b/samples/test/v3/translate_list_codes.test.js deleted file mode 100644 index 78ed075c..00000000 --- a/samples/test/v3/translate_list_codes.test.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_list_codes'; - -describe(REGION_TAG, () => { - it('should list available language codes', async () => { - const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const output = execSync(`node v3/${REGION_TAG}.js ${projectId}`); - assert.match(output, /Language Code: en/); - assert.match(output, /Language Code: fr/); - }); -}); diff --git a/samples/test/v3/translate_list_glossary.test.js b/samples/test/v3/translate_list_glossary.test.js deleted file mode 100644 index 06147262..00000000 --- a/samples/test/v3/translate_list_glossary.test.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_list_glossary'; - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - - it('should list glossaries in project', async () => { - const projectId = await translationClient.getProjectId(); - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location}` - ); - assert.match( - output, - /gs:\/\/cloud-samples-data\/translation\/glossary.csv/ - ); - assert.match(output, /DO_NOT_DELETE_TEST_GLOSSARY/); - }); -}); diff --git a/samples/test/v3/translate_list_language_names.test.js b/samples/test/v3/translate_list_language_names.test.js deleted file mode 100644 index 044a1af0..00000000 --- a/samples/test/v3/translate_list_language_names.test.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_list_language_names'; - -describe(REGION_TAG, () => { - it('should list available language names', async () => { - const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const output = execSync(`node v3/${REGION_TAG}.js ${projectId}`); - assert.match(output, /Language Code: en/); - assert.match(output, /Display Name: Anglais/); - assert.match(output, /Language Code: fr/); - assert.match(output, /Display Name: Français/); - }); -}); diff --git a/samples/test/v3/translate_translate_text.test.js b/samples/test/v3/translate_translate_text.test.js deleted file mode 100644 index 1212c49f..00000000 --- a/samples/test/v3/translate_translate_text.test.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_translate_text'; - -describe(REGION_TAG, () => { - it('should translate the input text', async () => { - const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const location = 'global'; - const text = '"Hello world"'; - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${text}` - ); - assert.match(output, /Translation: Здраво Свете/); - }); -}); diff --git a/samples/test/v3/translate_translate_text_with_glossary.test.js b/samples/test/v3/translate_translate_text_with_glossary.test.js deleted file mode 100644 index 526a4f24..00000000 --- a/samples/test/v3/translate_translate_text_with_glossary.test.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const GLOSSARY_ID = 'DO_NET_DELETE_TEST_GLOSSARY_ES'; -const REGION_TAG = 'translate_translate_text_with_glossary'; - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - - it('should translate text with a glossary in project', async () => { - const projectId = await translationClient.getProjectId(); - const input = 'directions'; - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${GLOSSARY_ID} ${input}` - ); - assert.match(output, /indicaciones/); - }); -}); diff --git a/samples/test/v3/translate_translate_text_with_glossary_and_model.test.js b/samples/test/v3/translate_translate_text_with_glossary_and_model.test.js deleted file mode 100644 index 429348cd..00000000 --- a/samples/test/v3/translate_translate_text_with_glossary_and_model.test.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const GLOSSARY_ID = 'DO_NOT_DELETE_TEST_GLOSSARY'; -const REGION_TAG = 'translate_translate_text_with_glossary_and_model'; - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const modelId = 'TRL8567014172607381504'; - - it('should translate text with a glossary and Automl model in project', async () => { - const projectId = await translationClient.getProjectId(); - const input = 'directions'; - const output = execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${GLOSSARY_ID} ${modelId} ${input}` - ); - assert.match(output, /Translation/); - }); -}); diff --git a/samples/test/v3/translate_translate_text_with_model.test.js b/samples/test/v3/translate_translate_text_with_model.test.js deleted file mode 100644 index 213a329a..00000000 --- a/samples/test/v3/translate_translate_text_with_model.test.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const REGION_TAG = 'translate_translate_text_with_model'; - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const modelId = 'TRL8567014172607381504'; - const input = 'Tell me how this ends'; - - it('should translate text with an automl model in project', async () => { - const projectId = await translationClient.getProjectId(); - const output = await execSync( - `node v3/${REGION_TAG}.js ${projectId} ${location} ${modelId} ${input}` - ); - assert.match(output, /Translated Content:/); - }); -}); diff --git a/samples/test/v3beta1/translate_batch_translate_document.test.js b/samples/test/v3beta1/translate_batch_translate_document.test.js deleted file mode 100644 index 79e69707..00000000 --- a/samples/test/v3beta1/translate_batch_translate_document.test.js +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, before, afterEach} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const {Storage} = require('@google-cloud/storage'); -const cp = require('child_process'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_batch_translate_document'; - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const bucketUuid = uuid.v4(); - const bucketName = `translation-${bucketUuid}/BATCH_OUTPUT/`; - const storage = new Storage(); - - before(async () => { - const projectId = await translationClient.getProjectId(); - - //Create bucket if needed - try { - await storage.createBucket(projectId, { - location: 'US', - storageClass: 'COLDLINE', - }); - } catch (error) { - if (error.code !== 409) { - //if it's not a duplicate bucket error, let the user know - console.error(error); - throw error; - } - } - }); - - it('should batch translate the input documents', async function () { - this.retries(3); - const projectId = await translationClient.getProjectId(); - const inputUri = 'gs://cloud-samples-data/translation/async_invoices/*'; - - const outputUri = `gs://${projectId}/${bucketName}`; - const output = execSync( - `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${inputUri} ${outputUri}` - ); - assert.match(output, /Total Pages: /); - - this.timeout(750000); - }); - - // Delete the folder from GCS for cleanup - afterEach(async () => { - const projectId = await translationClient.getProjectId(); - const options = { - prefix: `translation-${bucketUuid}`, - }; - - const bucket = await storage.bucket(projectId); - const [files] = await bucket.getFiles(options); - const length = files.length; - if (length > 0) { - await Promise.all(files.map(file => file.delete())); - } - }); -}); diff --git a/samples/test/v3beta1/translate_batch_translate_text_beta.test.js b/samples/test/v3beta1/translate_batch_translate_text_beta.test.js deleted file mode 100644 index c3c3ca0f..00000000 --- a/samples/test/v3beta1/translate_batch_translate_text_beta.test.js +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, before, afterEach} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const {Storage} = require('@google-cloud/storage'); -const cp = require('child_process'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_batch_translate_text_beta'; - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const bucketUuid = uuid.v4(); - const bucketName = `translation-${bucketUuid}/BATCH_TRANSLATION_OUTPUT/`; - const storage = new Storage(); - - before(async () => { - const projectId = await translationClient.getProjectId(); - - //Create bucket if needed - await storage - .createBucket(projectId, { - location: 'US', - storageClass: 'COLDLINE', - }) - .catch(error => { - if (error.code !== 409) { - //if it's not a duplicate bucket error, let the user know - console.error(error); - } - }); - }); - - it('should batch translate the input text', async function () { - this.retries(3); - const projectId = await translationClient.getProjectId(); - const inputUri = 'gs://cloud-samples-data/translation/text.txt'; - - const outputUri = `gs://${projectId}/${bucketName}`; - const output = execSync( - `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${inputUri} ${outputUri}` - ); - assert.match(output, /Total Characters: 13/); - assert.match(output, /Translated Characters: 13/); - - // batch translate fluctuates between 2 to 4 minutes. - this.timeout(300000); - }); - - // Delete the folder from GCS for cleanup - afterEach(async () => { - const projectId = await translationClient.getProjectId(); - const options = { - prefix: `translation-${bucketUuid}`, - }; - - const bucket = await storage.bucket(projectId); - const [files] = await bucket.getFiles(options); - const length = files.length; - if (length > 0) { - await Promise.all(files.map(file => file.delete())); - } - }); -}); diff --git a/samples/test/v3beta1/translate_create_glossary_beta.test.js b/samples/test/v3beta1/translate_create_glossary_beta.test.js deleted file mode 100644 index 19599088..00000000 --- a/samples/test/v3beta1/translate_create_glossary_beta.test.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, after} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_create_glossary_beta'; -const uuid = require('uuid'); - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const glossaryId = `test-glossary-${uuid.v4()}`; - - it('should create a glossary', async () => { - const projectId = await translationClient.getProjectId(); - const location = 'us-central1'; - const output = execSync( - `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${glossaryId}` - ); - assert.match( - output, - /gs:\/\/cloud-samples-data\/translation\/glossary.csv/ - ); - }); - - after('cleanup for glossary create', async () => { - const projectId = await translationClient.getProjectId(); - const location = 'us-central1'; - // Delete the glossary to clean up - const name = translationClient.glossaryPath( - projectId, - location, - glossaryId - ); - const request = { - parent: translationClient.locationPath(projectId, location), - name: name, - }; - - // Delete glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.deleteGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - }); -}); diff --git a/samples/test/v3beta1/translate_delete_glossary_beta.test.js b/samples/test/v3beta1/translate_delete_glossary_beta.test.js deleted file mode 100644 index 96de5994..00000000 --- a/samples/test/v3beta1/translate_delete_glossary_beta.test.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, before} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_delete_glossary_beta'; -const uuid = require('uuid'); - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const glossaryId = `test_glossary_${uuid.v4()}`; - - before(async () => { - // Add a glossary to be deleted - // const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const glossary = { - languageCodesSet: { - languageCodes: ['en', 'es'], - }, - inputConfig: { - gcsSource: { - inputUri: 'gs://cloud-samples-data/translation/glossary.csv', - }, - }, - name: translationClient.glossaryPath(projectId, location, glossaryId), - }; - - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - glossary: glossary, - }; - - // Create glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.createGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - }); - - it('should delete a glossary', async () => { - const projectId = await translationClient.getProjectId(); - - const output = execSync( - `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${glossaryId}` - ); - assert.include(output, glossaryId); - }); -}); diff --git a/samples/test/v3beta1/translate_detect_language_beta.test.js b/samples/test/v3beta1/translate_detect_language_beta.test.js deleted file mode 100644 index 814446d4..00000000 --- a/samples/test/v3beta1/translate_detect_language_beta.test.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_detect_language_beta'; - -describe(REGION_TAG, () => { - it('should detect the language of the input text', async () => { - const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const location = 'global'; - const text = "'Hæ sæta'"; - const output = execSync( - `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${text}` - ); - assert.match(output, /Language Code: is/); - assert.match(output, /Confidence: 1/); - }); -}); diff --git a/samples/test/v3beta1/translate_get_glossary_beta.test.js b/samples/test/v3beta1/translate_get_glossary_beta.test.js deleted file mode 100644 index 2d82f6b9..00000000 --- a/samples/test/v3beta1/translate_get_glossary_beta.test.js +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_get_glossary_beta'; -const uuid = require('uuid'); - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const glossaryId = `test-glossary-${uuid.v4()}`; - - before(async () => { - // Add a glossary to get - const projectId = await translationClient.getProjectId(); - const glossary = { - languageCodesSet: { - languageCodes: ['en', 'es'], - }, - inputConfig: { - gcsSource: { - inputUri: 'gs://cloud-samples-data/translation/glossary.csv', - }, - }, - name: translationClient.glossaryPath(projectId, location, glossaryId), - }; - - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - glossary: glossary, - }; - - // Create glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.createGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - }); - - it('should get a glossary', async () => { - const projectId = await translationClient.getProjectId(); - - const output = execSync( - `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${glossaryId}` - ); - assert.include(output, glossaryId); - }); - - after(async () => { - //delete the glossary we created - const projectId = await translationClient.getProjectId(); - const name = translationClient.glossaryPath( - projectId, - location, - glossaryId - ); - const request = { - parent: translationClient.locationPath(projectId, location), - name: name, - }; - - // Delete glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.deleteGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - }); -}); diff --git a/samples/test/v3beta1/translate_list_codes_beta.test.js b/samples/test/v3beta1/translate_list_codes_beta.test.js deleted file mode 100644 index ad345151..00000000 --- a/samples/test/v3beta1/translate_list_codes_beta.test.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_list_codes_beta'; - -describe(REGION_TAG, () => { - it('should list available language codes', async () => { - const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const output = execSync(`node v3beta1/${REGION_TAG}.js ${projectId}`); - assert.match(output, /Language Code: en/); - assert.match(output, /Language Code: fr/); - }); -}); diff --git a/samples/test/v3beta1/translate_list_glossary_beta.test.js b/samples/test/v3beta1/translate_list_glossary_beta.test.js deleted file mode 100644 index c6a86bf7..00000000 --- a/samples/test/v3beta1/translate_list_glossary_beta.test.js +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_list_glossary_beta'; - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const glossaryId = `test-glossary_${uuid.v4()}`; - - before(async () => { - // Add a glossary to be deleted - const projectId = await translationClient.getProjectId(); - - const glossary = { - languageCodesSet: { - languageCodes: ['en', 'es'], - }, - inputConfig: { - gcsSource: { - inputUri: 'gs://cloud-samples-data/translation/glossary.csv', - }, - }, - name: translationClient.glossaryPath(projectId, location, glossaryId), - }; - - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - glossary: glossary, - }; - - // Create glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.createGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - }); - - it('should list glossaries in project', async () => { - const projectId = await translationClient.getProjectId(); - const output = execSync( - `node v3beta1/${REGION_TAG}.js ${projectId} ${location}` - ); - assert.match( - output, - /gs:\/\/cloud-samples-data\/translation\/glossary.csv/ - ); - }); - - after(async () => { - const projectId = await translationClient.getProjectId(); - const name = translationClient.glossaryPath( - projectId, - location, - glossaryId - ); - const request = { - parent: translationClient.locationPath(projectId, location), - name: name, - }; - - // Delete glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.deleteGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - }); -}); diff --git a/samples/test/v3beta1/translate_list_language_names_beta.test.js b/samples/test/v3beta1/translate_list_language_names_beta.test.js deleted file mode 100644 index 7d588fed..00000000 --- a/samples/test/v3beta1/translate_list_language_names_beta.test.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_list_language_names_beta'; - -describe(REGION_TAG, () => { - it('should list available language names', async () => { - const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const output = execSync(`node v3beta1/${REGION_TAG}.js ${projectId}`); - assert.match(output, /Language Code: en/); - assert.match(output, /Display Name: Anglais/); - assert.match(output, /Language Code: fr/); - assert.match(output, /Display Name: Français/); - }); -}); diff --git a/samples/test/v3beta1/translate_translate_document.test.js b/samples/test/v3beta1/translate_translate_document.test.js deleted file mode 100644 index 2fc22363..00000000 --- a/samples/test/v3beta1/translate_translate_document.test.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_translate_document'; - -describe(REGION_TAG, () => { - it('should translate the input document', async () => { - const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const location = 'global'; - const inputUri = 'gs://cloud-samples-data/translation/fake_invoice.pdf'; - const output = execSync( - `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${inputUri}` - ); - assert.match(output, /Response: Mime Type/); - }); -}); diff --git a/samples/test/v3beta1/translate_translate_text_beta.test.js b/samples/test/v3beta1/translate_translate_text_beta.test.js deleted file mode 100644 index 39bdc4d8..00000000 --- a/samples/test/v3beta1/translate_translate_text_beta.test.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_translate_text_beta'; - -describe(REGION_TAG, () => { - it('should translate the input text', async () => { - const translationClient = new TranslationServiceClient(); - const projectId = await translationClient.getProjectId(); - const location = 'global'; - const text = '"Hello world"'; - const output = execSync( - `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${text}` - ); - assert.match(output, /Translation: Здраво Свете/); - }); -}); diff --git a/samples/test/v3beta1/translate_translate_text_with_glossary_beta.test.js b/samples/test/v3beta1/translate_translate_text_with_glossary_beta.test.js deleted file mode 100644 index 193edadf..00000000 --- a/samples/test/v3beta1/translate_translate_text_with_glossary_beta.test.js +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const REGION_TAG = 'translate_translate_text_with_glossary_beta'; -const uuid = require('uuid'); - -describe(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const glossaryId = `test-glossary-${uuid.v4()}`; - - before(async () => { - // Add a glossary to be translate with - const projectId = await translationClient.getProjectId(); - - const glossary = { - languageCodesSet: { - languageCodes: ['en', 'es'], - }, - inputConfig: { - gcsSource: { - inputUri: 'gs://cloud-samples-data/translation/glossary.csv', - }, - }, - name: translationClient.glossaryPath(projectId, location, glossaryId), - }; - - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - glossary: glossary, - }; - - // Create glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.createGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - }); - - it('should translate text with a glossary in project', async () => { - const projectId = await translationClient.getProjectId(); - const input = 'directions'; - const output = execSync( - `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${glossaryId} ${input}` - ); - assert.match(output, /indicaciones/); - }); - - after(async () => { - const projectId = await translationClient.getProjectId(); - const name = translationClient.glossaryPath( - projectId, - location, - glossaryId - ); - const request = { - parent: translationClient.locationPath(projectId, location), - name: name, - }; - - // Delete glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.deleteGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - }); -}); diff --git a/samples/test/v3beta1/translate_translate_text_with_model_beta.test.js b/samples/test/v3beta1/translate_translate_text_with_model_beta.test.js deleted file mode 100644 index af55ae6b..00000000 --- a/samples/test/v3beta1/translate_translate_text_with_model_beta.test.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const REGION_TAG = 'translate_translate_text_with_model_beta'; - -describe.skip(REGION_TAG, () => { - const translationClient = new TranslationServiceClient(); - const location = 'us-central1'; - const modelId = 'TRL123456789'; //TODO: Create model that can be used for testing - const input = 'Tell me how this ends'; - - it('should translate text with an automl model in project', async () => { - const projectId = await translationClient.getProjectId(); - const output = await execSync( - `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${modelId} ${input}` - ); - assert.match(output, /Translated Content: これがどのように終わるか教えて/); - }); -}); diff --git a/samples/translate.js b/samples/translate.js deleted file mode 100644 index d42e1685..00000000 --- a/samples/translate.js +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright 2017 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function detectLanguageSample(text) { - // [START translate_detect_language] - // Imports the Google Cloud client library - const {Translate} = require('@google-cloud/translate').v2; - - // Creates a client - const translate = new Translate(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const text = 'The text for which to detect language, e.g. Hello, world!'; - - // Detects the language. "text" can be a string for detecting the language of - // a single piece of text, or an array of strings for detecting the languages - // of multiple texts. - async function detectLanguage() { - let [detections] = await translate.detect(text); - detections = Array.isArray(detections) ? detections : [detections]; - console.log('Detections:'); - detections.forEach(detection => { - console.log(`${detection.input} => ${detection.language}`); - }); - } - - detectLanguage(); - // [END translate_detect_language] -} - -function listLanguagesSample() { - // [START translate_list_codes] - // Imports the Google Cloud client library - const {Translate} = require('@google-cloud/translate').v2; - - // Creates a client - const translate = new Translate(); - - async function listLanguages() { - // Lists available translation language with their names in English (the default). - const [languages] = await translate.getLanguages(); - - console.log('Languages:'); - languages.forEach(language => console.log(language)); - } - - listLanguages(); - // [END translate_list_codes] -} - -function listLanguagesWithTargetSample(target) { - // [START translate_list_language_names] - // Imports the Google Cloud client library - const {Translate} = require('@google-cloud/translate').v2; - - // Creates a client - const translate = new Translate(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const target = 'The target language for language names, e.g. ru'; - - async function listLanguagesWithTarget() { - // Lists available translation language with their names in a target language - const [languages] = await translate.getLanguages(target); - - console.log('Languages:'); - languages.forEach(language => console.log(language)); - } - - listLanguagesWithTarget(); - // [END translate_list_language_names] -} - -function translateTextSample(text, target) { - // [START translate_translate_text] - // Imports the Google Cloud client library - const {Translate} = require('@google-cloud/translate').v2; - - // Creates a client - const translate = new Translate(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const text = 'The text to translate, e.g. Hello, world!'; - // const target = 'The target language, e.g. ru'; - - async function translateText() { - // Translates the text into the target language. "text" can be a string for - // translating a single piece of text, or an array of strings for translating - // multiple texts. - let [translations] = await translate.translate(text, target); - translations = Array.isArray(translations) ? translations : [translations]; - console.log('Translations:'); - translations.forEach((translation, i) => { - console.log(`${text[i]} => (${target}) ${translation}`); - }); - } - - translateText(); - // [END translate_translate_text] -} - -function translateTextWithModelSample(text, target, model) { - // [START translate_text_with_model] - // Imports the Google Cloud client library - const {Translate} = require('@google-cloud/translate').v2; - - // Creates a client - const translate = new Translate(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const text = 'The text to translate, e.g. Hello, world!'; - // const target = 'The target language, e.g. ru'; - // const model = 'The model to use, e.g. nmt'; - - async function translateTextWithModel() { - const options = { - // The target language, e.g. "ru" - to: target, - // Make sure your project is on the allow list. - // Possible values are "base" and "nmt" - model: model, - }; - - // Translates the text into the target language. "text" can be a string for - // translating a single piece of text, or an array of strings for translating - // multiple texts. - let [translations] = await translate.translate(text, options); - translations = Array.isArray(translations) ? translations : [translations]; - console.log('Translations:'); - translations.forEach((translation, i) => { - console.log(`${text[i]} => (${target}) ${translation}`); - }); - } - - translateTextWithModel(); - // [END translate_text_with_model] -} - -require('yargs') - .demand(1) - .command( - 'detect ', - 'Detects the language of one or more strings.', - {}, - async opts => await detectLanguageSample(opts.text) - ) - .command( - 'list [target]', - 'Lists available translation languages. To language names in a language other than English, specify a target language.', - {}, - async opts => { - if (opts.target) { - await listLanguagesWithTargetSample(opts.target); - } else { - await listLanguagesSample(); - } - } - ) - .command( - 'translate ', - 'Translates one or more strings into the target language.', - {}, - async opts => await translateTextSample(opts.text, opts.toLang) - ) - .command( - 'translate-with-model ', - 'Translates one or more strings into the target language using the specified model.', - {}, - async opts => - await translateTextWithModelSample(opts.text, opts.toLang, opts.model) - ) - .example('node $0 detect "Hello world!"', 'Detects the language of a string.') - .example( - 'node $0 detect "Hello world!" "Goodbye"', - 'Detects the languages of multiple strings.' - ) - .example( - 'node $0 list', - 'Lists available translation languages with names in English.' - ) - .example( - 'node $0 list es', - 'Lists available translation languages with names in Spanish.' - ) - .example( - 'node $0 translate ru "Good morning!"', - 'Translates a string into Russian.' - ) - .example( - 'node $0 translate ru "Good morning!" "Good night!"', - 'Translates multiple strings into Russian.' - ) - .example( - 'node $0 translate-with-model ru nmt "Good morning!" "Good night!"', - 'Translates multiple strings into Russian using the Premium model.' - ) - .wrap(120) - .recommendCommands() - .epilogue('For more information, see https://cloud.google.com/translate/docs') - .help() - .strict().argv; diff --git a/samples/v3/translate_batch_translate_text.js b/samples/v3/translate_batch_translate_text.js deleted file mode 100644 index 196fa342..00000000 --- a/samples/v3/translate_batch_translate_text.js +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - inputUri = 'gs://cloud-samples-data/translation/text.txt', - outputUri = 'gs://YOUR_PROJECT_ID/translation/BATCH_TRANSLATION_OUTPUT/' -) { - // [START translate_v3_batch_translate_text] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'us-central1'; - // const inputUri = 'gs://cloud-samples-data/text.txt'; - // const outputUri = 'gs://YOUR_BUCKET_ID/path_to_store_results/'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - async function batchTranslateText() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - sourceLanguageCode: 'en', - targetLanguageCodes: ['ja'], - inputConfigs: [ - { - mimeType: 'text/plain', // mime types: text/plain, text/html - gcsSource: { - inputUri: inputUri, - }, - }, - ], - outputConfig: { - gcsDestination: { - outputUriPrefix: outputUri, - }, - }, - }; - - const options = {timeout: 240000}; - // Batch translate text using a long-running operation - const [operation] = await translationClient.batchTranslateText( - request, - options - ); - - // Wait for operation to complete. - const [response] = await operation.promise(); - - console.log(`Total Characters: ${response.totalCharacters}`); - console.log(`Translated Characters: ${response.translatedCharacters}`); - } - - batchTranslateText(); - // [END translate_v3_batch_translate_text] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_batch_translate_text_with_glossary.js b/samples/v3/translate_batch_translate_text_with_glossary.js deleted file mode 100644 index cd9b65e0..00000000 --- a/samples/v3/translate_batch_translate_text_with_glossary.js +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - inputUri = 'gs://cloud-samples-data/translation/text.txt', - outputUri = 'gs://YOUR_PROJECT_ID/translation/BATCH_TRANSLATION_OUTPUT/', - glossaryId = 'YOUR_GLOSSARY_ID' -) { - // [START translate_v3_batch_translate_text_with_glossary] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'us-central1'; - // const inputUri = 'gs://cloud-samples-data/text.txt'; - // const outputUri = 'gs://YOUR_BUCKET_ID/path_to_store_results/'; - // const glossaryId = 'YOUR_GLOSSARY_ID'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const client = new TranslationServiceClient(); - async function batchTranslateTextWithGlossary() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - sourceLanguageCode: 'en', - targetLanguageCodes: ['es'], - inputConfigs: [ - { - mimeType: 'text/plain', // mime types: text/plain, text/html - gcsSource: { - inputUri: inputUri, - }, - }, - ], - outputConfig: { - gcsDestination: { - outputUriPrefix: outputUri, - }, - }, - glossaries: { - es: { - glossary: `projects/${projectId}/locations/${location}/glossaries/${glossaryId}`, - }, - }, - }; - - const options = {timeout: 240000}; - // Create a job using a long-running operation - const [operation] = await client.batchTranslateText(request, options); - - // Wait for the operation to complete - const [response] = await operation.promise(); - - // Display the translation for each input text provided - console.log(`Total Characters: ${response.totalCharacters}`); - console.log(`Translated Characters: ${response.translatedCharacters}`); - } - - batchTranslateTextWithGlossary(); - // [END translate_v3_batch_translate_text_with_glossary] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_batch_translate_text_with_glossary_and_model.js b/samples/v3/translate_batch_translate_text_with_glossary_and_model.js deleted file mode 100644 index 802826c6..00000000 --- a/samples/v3/translate_batch_translate_text_with_glossary_and_model.js +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - inputUri = 'gs://cloud-samples-data/translation/text.txt', - outputUri = 'gs://YOUR_PROJECT_ID/translation/BATCH_TRANSLATION_OUTPUT/', - glossaryId = 'YOUR_GLOSSARY_ID', - modelId = 'YOUR_MODEL_ID' -) { - // [START translate_v3_batch_translate_text_with_glossary_and_model] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'us-central1'; - // const inputUri = 'gs://cloud-samples-data/text.txt'; - // const outputUri = 'gs://YOUR_BUCKET_ID/path_to_store_results/'; - // const glossaryId = 'YOUR_GLOSSARY_ID'; - // const modelId = 'YOUR_MODEL_ID'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const client = new TranslationServiceClient(); - async function batchTranslateTextWithGlossaryAndModel() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - sourceLanguageCode: 'en', - targetLanguageCodes: ['ja'], - inputConfigs: [ - { - mimeType: 'text/plain', // mime types: text/plain, text/html - gcsSource: { - inputUri: inputUri, - }, - }, - ], - outputConfig: { - gcsDestination: { - outputUriPrefix: outputUri, - }, - }, - glossaries: { - ja: { - glossary: `projects/${projectId}/locations/${location}/glossaries/${glossaryId}`, - }, - }, - models: { - ja: `projects/${projectId}/locations/${location}/models/${modelId}`, - }, - }; - - const options = {timeout: 240000}; - // Create a job using a long-running operation - const [operation] = await client.batchTranslateText(request, options); - - // Wait for operation to complete - const [response] = await operation.promise(); - - // Display the translation for each input text provided - console.log(`Total Characters: ${response.totalCharacters}`); - console.log(`Translated Characters: ${response.translatedCharacters}`); - } - - batchTranslateTextWithGlossaryAndModel(); - // [END translate_v3_batch_translate_text_with_glossary_and_model] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_batch_translate_text_with_model.js b/samples/v3/translate_batch_translate_text_with_model.js deleted file mode 100644 index 69f7b49a..00000000 --- a/samples/v3/translate_batch_translate_text_with_model.js +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - inputUri = 'gs://cloud-samples-data/translation/text.txt', - outputUri = 'gs://YOUR_PROJECT_ID/translation/BATCH_TRANSLATION_OUTPUT/', - modelId = 'YOUR_MODEL_ID' -) { - // [START translate_v3_batch_translate_text_with_model] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'us-central1'; - // const inputUri = 'gs://cloud-samples-data/text.txt'; - // const outputUri = 'gs://YOUR_BUCKET_ID/path_to_store_results/'; - // const modelId = 'YOUR_MODEL_ID'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const client = new TranslationServiceClient(); - async function batchTranslateTextWithModel() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - sourceLanguageCode: 'en', - targetLanguageCodes: ['ja'], - inputConfigs: [ - { - mimeType: 'text/plain', // mime types: text/plain, text/html - gcsSource: { - inputUri: inputUri, - }, - }, - ], - outputConfig: { - gcsDestination: { - outputUriPrefix: outputUri, - }, - }, - models: { - ja: `projects/${projectId}/locations/${location}/models/${modelId}`, - }, - }; - - const options = {timeout: 240000}; - // Create a job using a long-running operation - const [operation] = await client.batchTranslateText(request, options); - - // Wait for the operation to complete - const [response] = await operation.promise(); - - // Display the translation for each input text provided - console.log(`Total Characters: ${response.totalCharacters}`); - console.log(`Translated Characters: ${response.translatedCharacters}`); - } - - batchTranslateTextWithModel(); - // [END translate_v3_batch_translate_text_with_model] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_create_glossary.js b/samples/v3/translate_create_glossary.js deleted file mode 100644 index b7ccf7ed..00000000 --- a/samples/v3/translate_create_glossary.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - glossaryId = 'your-glossary-display-name' -) { - // [START translate_v3_create_glossary] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - // const glossaryId = 'your-glossary-display-name'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function createGlossary() { - // Construct glossary - const glossary = { - languageCodesSet: { - languageCodes: ['en', 'es'], - }, - inputConfig: { - gcsSource: { - inputUri: 'gs://cloud-samples-data/translation/glossary.csv', - }, - }, - name: `projects/${projectId}/locations/${location}/glossaries/${glossaryId}`, - }; - - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - glossary: glossary, - }; - - // Create glossary using a long-running operation - const [operation] = await translationClient.createGlossary(request); - - // Wait for the operation to complete - await operation.promise(); - - console.log('Created glossary:'); - console.log(`InputUri ${request.glossary.inputConfig.gcsSource.inputUri}`); - } - - createGlossary(); - // [END translate_v3_create_glossary] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_delete_glossary.js b/samples/v3/translate_delete_glossary.js deleted file mode 100644 index 270515a7..00000000 --- a/samples/v3/translate_delete_glossary.js +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - glossaryId = 'glossary-id' -) { - // [START translate_v3_delete_glossary] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - // const glossaryId = 'YOUR_GLOSSARY_ID'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function deleteGlossary() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - name: `projects/${projectId}/locations/${location}/glossaries/${glossaryId}`, - }; - - // Delete glossary using a long-running operation - const [operation] = await translationClient.deleteGlossary(request); - - // Wait for operation to complete. - const [response] = await operation.promise(); - - console.log(`Deleted glossary: ${response.name}`); - } - - deleteGlossary(); - // [END translate_v3_delete_glossary] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_detect_language.js b/samples/v3/translate_detect_language.js deleted file mode 100644 index 907a9322..00000000 --- a/samples/v3/translate_detect_language.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'global', - text = 'text to translate' -) { - // [START translate_v3_detect_language] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - // const text = 'text to translate'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function detectLanguage() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - content: text, - }; - - // Run request - const [response] = await translationClient.detectLanguage(request); - - console.log('Detected Languages:'); - for (const language of response.languages) { - console.log(`Language Code: ${language.languageCode}`); - console.log(`Confidence: ${language.confidence}`); - } - } - - detectLanguage(); - // [END translate_v3_detect_language] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_get_glossary.js b/samples/v3/translate_get_glossary.js deleted file mode 100644 index b234376a..00000000 --- a/samples/v3/translate_get_glossary.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - glossaryId = 'glossary-id' -) { - // [START translate_v3_get_glossary] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - // const glossaryId = 'YOUR_GLOSSARY_ID'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function getGlossary() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - name: `projects/${projectId}/locations/${location}/glossaries/${glossaryId}`, - }; - - // Get glossary - const [response] = await translationClient.getGlossary(request); - - console.log(`Glossary name: ${response.name}`); - console.log(`Entry count: ${response.entryCount}`); - console.log(`Input URI: ${response.inputConfig.gcsSource.inputUri}`); - } - - getGlossary(); - // [END translate_v3_get_glossary] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_get_supported_languages.js b/samples/v3/translate_get_supported_languages.js deleted file mode 100644 index 63ccbbbf..00000000 --- a/samples/v3/translate_get_supported_languages.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main(projectId = 'YOUR_PROJECT_ID', location = 'global') { - // [START translate_v3_get_supported_languages] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function getSupportedLanguages() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - }; - - // Get supported languages - const [response] = await translationClient.getSupportedLanguages(request); - - for (const language of response.languages) { - // Supported language code, generally consisting of its ISO 639-1 identifier, for - // example, 'en', 'ja'. In certain cases, BCP-47 codes including language and - // region identifiers are returned (for example, 'zh-TW' and 'zh-CN') - console.log(`Language - Language Code: ${language.languageCode}`); - // Human readable name of the language localized in the display language specified - // in the request. - console.log(`Language - Display Name: ${language.displayName}`); - // Can be used as source language. - console.log(`Language - Support Source: ${language.supportSource}`); - // Can be used as target language. - console.log(`Language - Support Target: ${language.supportTarget}`); - } - } - - getSupportedLanguages(); - // [END translate_v3_get_supported_languages] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_get_supported_languages_for_target.js b/samples/v3/translate_get_supported_languages_for_target.js deleted file mode 100644 index d37cc098..00000000 --- a/samples/v3/translate_get_supported_languages_for_target.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main(projectId = 'YOUR_PROJECT_ID', location = 'global') { - // [START translate_v3_get_supported_languages_for_target] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function getSupportedLanguages() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - displayLanguageCode: 'en', - }; - - // Get supported languages - const [response] = await translationClient.getSupportedLanguages(request); - - for (const language of response.languages) { - // Supported language code, generally consisting of its ISO 639-1 identifier, for - // example, 'en', 'ja'. In certain cases, BCP-47 codes including language and - // region identifiers are returned (for example, 'zh-TW' and 'zh-CN') - console.log(`Language - Language Code: ${language.languageCode}`); - // Human readable name of the language localized in the display language specified - // in the request. - console.log(`Language - Display Name: ${language.displayName}`); - // Can be used as source language. - console.log(`Language - Support Source: ${language.supportSource}`); - // Can be used as target language. - console.log(`Language - Support Target: ${language.supportTarget}`); - } - } - - getSupportedLanguages(); - // [END translate_v3_get_supported_languages_for_target] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_list_codes.js b/samples/v3/translate_list_codes.js deleted file mode 100644 index fc1ce704..00000000 --- a/samples/v3/translate_list_codes.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main(projectId = 'YOUR_PROJECT_ID', location = 'global') { - // [START translate_v3_list_codes] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function listLanguages() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - }; - - // Run request - const [response] = await translationClient.getSupportedLanguages(request); - - console.log('Supported languages:'); - for (const language of response.languages) { - console.log(`Language Code: ${language.languageCode}`); - } - } - - listLanguages(); - // [END translate_v3_list_codes] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_list_glossary.js b/samples/v3/translate_list_glossary.js deleted file mode 100644 index 8aacfb2b..00000000 --- a/samples/v3/translate_list_glossary.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main(projectId = 'YOUR_PROJECT_ID', location = 'us-central1') { - // [START translate_v3_list_glossary] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function listGlossaries() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - }; - - // Run request - const [response] = await translationClient.listGlossaries(request); - - for (const glossary of response) { - console.log(`Name: ${glossary.name}`); - console.log(`Entry count: ${glossary.entryCount}`); - console.log(`Input uri: ${glossary.inputConfig.gcsSource.inputUri}`); - for (const languageCode of glossary.languageCodesSet.languageCodes) { - console.log(`Language code: ${languageCode}`); - } - } - } - - listGlossaries(); - // [END translate_v3_list_glossary] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_list_language_names.js b/samples/v3/translate_list_language_names.js deleted file mode 100644 index 4146dd96..00000000 --- a/samples/v3/translate_list_language_names.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main(projectId = 'YOUR_PROJECT_ID', location = 'global') { - // [START translate_v3_list_language_names] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function listLanguages() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - displayLanguageCode: 'fr', - }; - - // Run request - const [response] = await translationClient.getSupportedLanguages(request); - - console.log('Supported languages:'); - for (const language of response.languages) { - console.log(`Language Code: ${language.languageCode}`); - console.log(`Display Name: ${language.displayName}`); - } - } - - listLanguages(); - // [END translate_v3_list_language_names] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_translate_text.js b/samples/v3/translate_translate_text.js deleted file mode 100644 index 7d61f6b1..00000000 --- a/samples/v3/translate_translate_text.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'global', - text = 'text to translate' -) { - // [START translate_v3_translate_text] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - // const text = 'text to translate'; - - // [START translate_v3_translate_text_0] - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - // [END translate_v3_translate_text_0] - - // [START translate_v3_translate_text_1] - // Instantiates a client - const translationClient = new TranslationServiceClient(); - // [END translate_v3_translate_text_1] - - async function translateText() { - // [START translate_v3_translate_text_2] - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - contents: [text], - mimeType: 'text/plain', // mime types: text/plain, text/html - sourceLanguageCode: 'en', - targetLanguageCode: 'sr-Latn', - }; - // [END translate_v3_translate_text_2] - - // [START translate_v3_translate_text_3] - // Run request - const [response] = await translationClient.translateText(request); - - for (const translation of response.translations) { - console.log(`Translation: ${translation.translatedText}`); - } - // [END translate_v3_translate_text_3] - } - - translateText(); - // [END translate_v3_translate_text] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_translate_text_with_glossary.js b/samples/v3/translate_translate_text_with_glossary.js deleted file mode 100644 index 4c0d1507..00000000 --- a/samples/v3/translate_translate_text_with_glossary.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - glossaryId = 'glossary', - text = 'text to translate' -) { - // [START translate_v3_translate_text_with_glossary] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - // const glossaryId = 'YOUR_GLOSSARY_ID'; - // const text = 'text to translate'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - async function translateTextWithGlossary() { - const glossaryConfig = { - glossary: `projects/${projectId}/locations/${location}/glossaries/${glossaryId}`, - }; - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - contents: [text], - mimeType: 'text/plain', // mime types: text/plain, text/html - sourceLanguageCode: 'en', - targetLanguageCode: 'es', - glossaryConfig: glossaryConfig, - }; - - // Run request - const [response] = await translationClient.translateText(request); - - for (const translation of response.glossaryTranslations) { - console.log(`Translation: ${translation.translatedText}`); - } - } - - translateTextWithGlossary(); - // [END translate_v3_translate_text_with_glossary] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_translate_text_with_glossary_and_model.js b/samples/v3/translate_translate_text_with_glossary_and_model.js deleted file mode 100644 index 25854e6d..00000000 --- a/samples/v3/translate_translate_text_with_glossary_and_model.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - glossaryId = 'glossary', - modelId = 'YOUR_MODEL_ID', - text = 'text to translate' -) { - // [START translate_v3_translate_text_with_glossary_and_model] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'us-central1'; - // const glossaryId = 'YOUR_GLOSSARY_ID'; - // const modelId = 'YOUR_MODEL_ID'; - // const text = 'text to translate'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - async function translateTextWithGlossaryAndModel() { - const glossaryConfig = { - glossary: `projects/${projectId}/locations/${location}/glossaries/${glossaryId}`, - }; - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - contents: [text], - mimeType: 'text/plain', // mime types: text/plain, text/html - sourceLanguageCode: 'en', - targetLanguageCode: 'ja', - glossaryConfig: glossaryConfig, - model: `projects/${projectId}/locations/${location}/models/${modelId}`, - }; - - // Run request - const [response] = await translationClient.translateText(request); - - for (const translation of response.glossaryTranslations) { - console.log(`Translation: ${translation.translatedText}`); - } - } - - translateTextWithGlossaryAndModel(); - // [END translate_v3_translate_text_with_glossary_and_model] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3/translate_translate_text_with_model.js b/samples/v3/translate_translate_text_with_model.js deleted file mode 100644 index 8efdc8b3..00000000 --- a/samples/v3/translate_translate_text_with_model.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - modelId = 'model-id', - text = 'text to translate' -) { - // [START translate_v3_translate_text_with_model] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'us-central1'; - // const modelId = 'YOUR_MODEL_ID'; - // const text = 'text to translate'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - async function translateTextWithModel() { - // Construct request - const request = { - parent: `projects/${projectId}/locations/${location}`, - contents: [text], - mimeType: 'text/plain', // mime types: text/plain, text/html - sourceLanguageCode: 'en', - targetLanguageCode: 'ja', - model: `projects/${projectId}/locations/${location}/models/${modelId}`, - }; - - // Run request - const [response] = await translationClient.translateText(request); - - for (const translation of response.translations) { - console.log(`Translated Content: ${translation.translatedText}`); - } - } - - translateTextWithModel(); - // [END translate_v3_translate_text_with_model] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_batch_translate_document.js b/samples/v3beta1/translate_batch_translate_document.js deleted file mode 100644 index 6d487ea9..00000000 --- a/samples/v3beta1/translate_batch_translate_document.js +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - inputUri = 'gs://cloud-samples-data/translation/async_invoices/*', - outputUri = 'gs://YOUR_PROJECT_ID/translation/BATCH_DOCUMENT_TRANSLATION_OUTPUT/' -) { - // [START translate_batch_translate_document] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'us-central1'; - // const inputUri = 'path_to_your_files'; - // const outputUri = 'path_to_your_output_bucket'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - const documentInputConfig = { - gcsSource: { - inputUri: inputUri, - }, - }; - - async function batchTranslateDocument() { - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - documentInputConfig: documentInputConfig, - sourceLanguageCode: 'en-US', - targetLanguageCodes: ['sr-Latn'], - inputConfigs: [ - { - gcsSource: { - inputUri: inputUri, - }, - }, - ], - outputConfig: { - gcsDestination: { - outputUriPrefix: outputUri, - }, - }, - }; - - // Batch translate documents using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.batchTranslateDocument(request); - - // Wait for operation to complete. - const [response] = await operation.promise(); - - console.log(`Total Pages: ${response.totalPages}`); - } - - batchTranslateDocument(); - // [END translate_batch_translate_document] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_batch_translate_text_beta.js b/samples/v3beta1/translate_batch_translate_text_beta.js deleted file mode 100644 index f6413b2c..00000000 --- a/samples/v3beta1/translate_batch_translate_text_beta.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - inputUri = 'gs://cloud-samples-data/translation/text.txt', - outputUri = 'gs://YOUR_PROJECT_ID/translation/BATCH_TRANSLATION_OUTPUT/' -) { - // [START translate_batch_translate_text_beta] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'us-central1'; - // const text = 'text to translate'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - async function batchTranslateText() { - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - sourceLanguageCode: 'en-US', - targetLanguageCodes: ['sr-Latn'], - inputConfigs: [ - { - mimeType: 'text/plain', // mime types: text/plain, text/html - gcsSource: { - inputUri: inputUri, - }, - }, - ], - outputConfig: { - gcsDestination: { - outputUriPrefix: outputUri, - }, - }, - }; - - // Batch translate text using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.batchTranslateText(request); - - // Wait for operation to complete. - const [response] = await operation.promise(); - - console.log(`Total Characters: ${response.totalCharacters}`); - console.log(`Translated Characters: ${response.translatedCharacters}`); - } - - batchTranslateText(); - // [END translate_batch_translate_text_beta] -} - -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_create_glossary_beta.js b/samples/v3beta1/translate_create_glossary_beta.js deleted file mode 100644 index 5b50459f..00000000 --- a/samples/v3beta1/translate_create_glossary_beta.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - glossaryId = 'glossary-id' -) { - // [START translate_create_glossary_beta] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function createGlossary() { - // Construct glossary - const glossary = { - languageCodesSet: { - languageCodes: ['en', 'es'], - }, - inputConfig: { - gcsSource: { - inputUri: 'gs://cloud-samples-data/translation/glossary.csv', - }, - }, - name: translationClient.glossaryPath(projectId, location, glossaryId), - }; - - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - glossary: glossary, - }; - - // Create glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.createGlossary(request); - - // Wait for operation to complete. - await operation.promise(); - - console.log('Created glossary:'); - console.log(`InputUri ${request.glossary.inputConfig.gcsSource.inputUri}`); - } - - createGlossary(); - // [END translate_create_glossary_beta] -} - -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_delete_glossary_beta.js b/samples/v3beta1/translate_delete_glossary_beta.js deleted file mode 100644 index 9eef42fa..00000000 --- a/samples/v3beta1/translate_delete_glossary_beta.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - glossaryId = 'glossary-id' -) { - // [START translate_delete_glossary_beta] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function deleteGlossary() { - // Construct request - const name = translationClient.glossaryPath( - projectId, - location, - glossaryId - ); - const request = { - parent: translationClient.locationPath(projectId, location), - name: name, - }; - - // Delete glossary using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await translationClient.deleteGlossary(request); - - // Wait for operation to complete. - const [response] = await operation.promise(); - - console.log(`Deleted glossary: ${response.name}`); - } - - deleteGlossary(); - // [END translate_delete_glossary_beta] -} - -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_detect_language_beta.js b/samples/v3beta1/translate_detect_language_beta.js deleted file mode 100644 index 1746eb57..00000000 --- a/samples/v3beta1/translate_detect_language_beta.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'global', - text = 'text to translate' -) { - // [START translate_detect_language_beta] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function detectLanguage() { - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - content: text, - }; - - // Run request - const [response] = await translationClient.detectLanguage(request); - - console.log('Detected Languages:'); - for (const language of response.languages) { - console.log(`Language Code: ${language.languageCode}`); - console.log(`Confidence: ${language.confidence}`); - } - } - - detectLanguage(); - // [END translate_detect_language_beta] -} - -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_get_glossary_beta.js b/samples/v3beta1/translate_get_glossary_beta.js deleted file mode 100644 index ce565681..00000000 --- a/samples/v3beta1/translate_get_glossary_beta.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - glossaryId = 'glossary-id' -) { - // [START translate_get_glossary_beta] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function getGlossary() { - // Construct request - const name = translationClient.glossaryPath( - projectId, - location, - glossaryId - ); - const request = { - parent: translationClient.locationPath(projectId, location), - name: name, - }; - - // Get glossary - const [response] = await translationClient.getGlossary(request); - - console.log(`Got glossary: ${response.name}`); - } - - getGlossary(); - // [END translate_get_glossary_beta] -} - -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_list_codes_beta.js b/samples/v3beta1/translate_list_codes_beta.js deleted file mode 100644 index f67c1d34..00000000 --- a/samples/v3beta1/translate_list_codes_beta.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main(projectId = 'YOUR_PROJECT_ID', location = 'global') { - // [START translate_list_codes_beta] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function listLanguages() { - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - }; - - // Run request - const [response] = await translationClient.getSupportedLanguages(request); - - console.log('Supported languages:'); - for (const language of response.languages) { - console.log(`Language Code: ${language.languageCode}`); - } - } - - listLanguages(); - // [END translate_list_codes_beta] -} - -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_list_glossary_beta.js b/samples/v3beta1/translate_list_glossary_beta.js deleted file mode 100644 index aa5e1f9c..00000000 --- a/samples/v3beta1/translate_list_glossary_beta.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main(projectId = 'YOUR_PROJECT_ID', location = 'us-central1') { - // [START translate_list_glossary_beta] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function listGlossaries() { - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - }; - - // Run request - const [response] = await translationClient.listGlossaries(request); - - for (const glossary of response) { - console.log(`Name: ${glossary.name}`); - console.log(`Entry count: ${glossary.entryCount}`); - console.log(`Input uri: ${glossary.inputConfig.gcsSource.inputUri}`); - for (const languageCode of glossary.languageCodesSet.languageCodes) { - console.log(`Language code: ${languageCode}`); - } - } - } - - listGlossaries(); - // [END translate_list_glossary_beta] -} - -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_list_language_names_beta.js b/samples/v3beta1/translate_list_language_names_beta.js deleted file mode 100644 index 4fe0103b..00000000 --- a/samples/v3beta1/translate_list_language_names_beta.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main(projectId = 'YOUR_PROJECT_ID', location = 'global') { - // [START translate_list_language_names_beta] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - async function listLanguages() { - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - displayLanguageCode: 'fr', - }; - - // Run request - const [response] = await translationClient.getSupportedLanguages(request); - - console.log('Supported languages:'); - for (const language of response.languages) { - console.log(`Language Code: ${language.languageCode}`); - console.log(`Display Name: ${language.displayName}`); - } - } - - listLanguages(); - // [END translate_list_language_names_beta] -} - -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_translate_document.js b/samples/v3beta1/translate_translate_document.js deleted file mode 100644 index 65de3af6..00000000 --- a/samples/v3beta1/translate_translate_document.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'global', - inputUri = 'path_to_your_file' -) { - // [START translate_translate_document] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - // const inputUri = 'path_to_your_file'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - - const documentInputConfig = { - gcsSource: { - inputUri: inputUri, - }, - }; - - async function translateDocument() { - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - documentInputConfig: documentInputConfig, - sourceLanguageCode: 'en-US', - targetLanguageCode: 'sr-Latn', - }; - - // Run request - const [response] = await translationClient.translateDocument(request); - - console.log( - `Response: Mime Type - ${response.documentTranslation.mimeType}` - ); - } - - translateDocument(); - // [END translate_translate_document] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_translate_text_beta.js b/samples/v3beta1/translate_translate_text_beta.js deleted file mode 100644 index f1854ba5..00000000 --- a/samples/v3beta1/translate_translate_text_beta.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'global', - text = 'text to translate' -) { - // [START translate_translate_text_beta] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - // const text = 'text to translate'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - async function translateText() { - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - contents: [text], - mimeType: 'text/plain', // mime types: text/plain, text/html - sourceLanguageCode: 'en-US', - targetLanguageCode: 'sr-Latn', - }; - - // Run request - const [response] = await translationClient.translateText(request); - - for (const translation of response.translations) { - console.log(`Translation: ${translation.translatedText}`); - } - } - - translateText(); - // [END translate_translate_text_beta] -} - -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_translate_text_with_glossary_beta.js b/samples/v3beta1/translate_translate_text_with_glossary_beta.js deleted file mode 100644 index 4787b312..00000000 --- a/samples/v3beta1/translate_translate_text_with_glossary_beta.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - glossaryId = 'glossary', - text = 'text to translate' -) { - // [START translate_translate_text_with_glossary_beta] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - async function translateTextWithGlossary() { - const glossary = translationClient.glossaryPath( - projectId, - location, - glossaryId - ); - const glossaryConfig = { - glossary: glossary, - }; - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - contents: [text], - mimeType: 'text/plain', // mime types: text/plain, text/html - sourceLanguageCode: 'en-US', - targetLanguageCode: 'es', - glossaryConfig: glossaryConfig, - }; - - // Run request - const [response] = await translationClient.translateText(request); - - for (const translation of response.glossaryTranslations) { - console.log(`Translation: ${translation.translatedText}`); - } - } - - translateTextWithGlossary(); - // [END translate_translate_text_with_glossary_beta] -} - -main(...process.argv.slice(2)); diff --git a/samples/v3beta1/translate_translate_text_with_model_beta.js b/samples/v3beta1/translate_translate_text_with_model_beta.js deleted file mode 100644 index c6c3eb29..00000000 --- a/samples/v3beta1/translate_translate_text_with_model_beta.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -'use strict'; - -function main( - projectId = 'YOUR_PROJECT_ID', - location = 'us-central1', - modelId = 'model-id', - text = 'text to translate' -) { - // [START translate_text_with_model_beta] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'global'; - // const modelId = 'YOUR_MODEL_ID'; - - // Imports the Google Cloud Translation library - const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; - const automl = require('@google-cloud/automl'); - - // Instantiates a client - const translationClient = new TranslationServiceClient(); - const autoMLClient = new automl.AutoMlClient(); - async function translateTextWithModel() { - const model = autoMLClient.modelPath(projectId, location, modelId); - // Construct request - const request = { - parent: translationClient.locationPath(projectId, location), - contents: [text], - mimeType: 'text/plain', // mime types: text/plain, text/html - sourceLanguageCode: 'en-US', - targetLanguageCode: 'ja', - model: model, - }; - - // Run request - const [response] = await translationClient.translateText(request); - - for (const translation of response.translations) { - console.log(`Translated Content: ${translation.translatedText}`); - } - } - - translateTextWithModel(); - // [END translate_text_with_model_beta] -} - -main(...process.argv.slice(2));