Skip to content

Commit

Permalink
docs: generate new samples/README.md, README.md (#268)
Browse files Browse the repository at this point in the history
* Add README with instructions to run v3 translate

* Remove extra blank line

* docs: generate new samples/README.md, README.md

* docs: finish porting over changes to samples/README.md

* docs: add issue tracker link

* chore: address code review

* Move region tag
  • Loading branch information
bcoe authored and leahecole committed May 20, 2019
1 parent a71f2a5 commit 299e5b6
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 221 deletions.
16 changes: 0 additions & 16 deletions packages/google-cloud-translate/.cloud-repo-tools.json

This file was deleted.

62 changes: 62 additions & 0 deletions packages/google-cloud-translate/.readme-partials.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
title: |-
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.
samples_body: |-
### 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 <CLI argument 0> <CLI argument 1>
```
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"
```
13 changes: 13 additions & 0 deletions packages/google-cloud-translate/.repo-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "translate",
"name_pretty": "Cloud Translation",
"product_documentation": "https://cloud.google.com/translate/docs/",
"client_documentation": "https://cloud.google.com/nodejs/docs/reference/translate/latest/",
"issue_tracker": "https://issuetracker.google.com/savedsearches/559749",
"release_level": "ga",
"language": "nodejs",
"repo": "googleapis/nodejs-translate",
"distribution_name": "@google-cloud/translate",
"api_id": "translate.googleapis.com",
"requires_billing": true
}
128 changes: 72 additions & 56 deletions packages/google-cloud-translate/README.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,120 @@
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
[//]: # "To regenerate it, use `npm run generate-scaffolding`."
[//]: # "To regenerate it, use `python -m synthtool`."
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# [Google Cloud Translation API: Node.js Client](https://github.com/googleapis/nodejs-translate)
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.

[![release level](https://img.shields.io/badge/release%20level-general%20availability%20%28GA%29-brightgreen.svg?style&#x3D;flat)](https://cloud.google.com/terms/launch-stages)

[![release level](https://img.shields.io/badge/release%20level-general%20availability%20%28GA%29-brightgreen.svg?style=flat)](https://cloud.google.com/terms/launch-stages)
[![npm version](https://img.shields.io/npm/v/@google-cloud/translate.svg)](https://www.npmjs.org/package/@google-cloud/translate)
[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-translate/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-translate)

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.


* [Using the client library](#using-the-client-library)

Cloud Translation API Client Library for Node.js


* [Cloud Translation Node.js Client API Reference][client-docs]
* [Cloud Translation Documentation][product-docs]
* [github.com/googleapis/nodejs-translate](https://github.com/googleapis/nodejs-translate)

Read more about the client libraries for Cloud APIs, including the older
Google APIs Client Libraries, in [Client Libraries Explained][explained].

[explained]: https://cloud.google.com/apis/docs/client-libraries-explained

**Table of contents:**


* [Quickstart](#quickstart)
* [Before you begin](#before-you-begin)
* [Installing the client library](#installing-the-client-library)
* [Using the client library](#using-the-client-library)
* [Samples](#samples)
* [Versioning](#versioning)
* [Contributing](#contributing)
* [License](#license)

## Using the client library
## Quickstart

1. [Select or create a Cloud Platform project][projects].
### Before you begin

1. [Select or create a Cloud Platform project][projects].
1. [Enable billing for your project][billing].

1. [Enable the Google Cloud Translation API API][enable_api].

1. [Enable the Cloud Translation API][enable_api].
1. [Set up authentication with a service account][auth] so you can access the
API from your local workstation.

1. Install the client library:
### Installing the client library

```bash
npm install @google-cloud/translate
```

npm install --save @google-cloud/translate

1. Try an example:
### Using the client library

```javascript
// Imports the Google Cloud client library
const {Translate} = require('@google-cloud/translate');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';

// Instantiates a client
const translate = new Translate({
projectId: projectId,
});

// The text to translate
const text = 'Hello, world!';
// The target language
const target = 'ru';

// Translates some text into Russian
translate
.translate(text, target)
.then(results => {
const translation = results[0];

console.log(`Text: ${text}`);
console.log(`Translation: ${translation}`);
})
.catch(err => {
console.error('ERROR:', err);
});
async function main(
projectId = 'YOUR_PROJECT_ID' // Your GCP Project Id
) {
// Imports the Google Cloud client library
const {Translate} = require('@google-cloud/translate');

// Instantiates a client
const translate = new Translate({projectId});

// 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}`);
}

```



## Samples

Samples are in the [`samples/`](https://github.com/googleapis/nodejs-translate/tree/master/samples) directory. The samples' `README.md`
has instructions for running the samples.

| Sample | Source Code | Try it |
| --------------------------- | --------------------------------- | ------ |
| Quickstart | [source code](https://github.com/googleapis/nodejs-translate/blob/master/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) |
| Translate | [source code](https://github.com/googleapis/nodejs-translate/blob/master/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) |

The [Cloud Translation API Node.js Client API Reference][client-docs] documentation


The [Cloud Translation Node.js Client API Reference][client-docs] documentation
also contains samples.

## Versioning

This library follows [Semantic Versioning](http://semver.org/).


This library is considered to be **General Availability (GA)**. This means it
is stable; the code surface will not change in backwards-incompatible ways
unless absolutely necessary (e.g. because of critical security issues) or with
an extensive deprecation period. Issues and requests against **GA** libraries
are addressed with the highest priority.





More Information: [Google Cloud Platform Launch Stages][launch_stages]

[launch_stages]: https://cloud.google.com/terms/launch-stages
Expand All @@ -101,22 +129,10 @@ Apache Version 2.0

See [LICENSE](https://github.com/googleapis/nodejs-translate/blob/master/LICENSE)

## What's Next

* [Cloud Translation API Documentation][product-docs]
* [Cloud Translation API Node.js Client API Reference][client-docs]
* [github.com/googleapis/nodejs-translate](https://github.com/googleapis/nodejs-translate)

Read more about the client libraries for Cloud APIs, including the older
Google APIs Client Libraries, in [Client Libraries Explained][explained].

[explained]: https://cloud.google.com/apis/docs/client-libraries-explained

[client-docs]: https://cloud.google.com/nodejs/docs/reference/translate/latest/
[product-docs]: https://cloud.google.com/translate/docs
[product-docs]: https://cloud.google.com/translate/docs/
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
[projects]: https://console.cloud.google.com/project
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=translate.googleapis.com
[auth]: https://cloud.google.com/docs/authentication/getting-started

[auth]: https://cloud.google.com/docs/authentication/getting-started
2 changes: 0 additions & 2 deletions packages/google-cloud-translate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"scripts": {
"docs": "jsdoc -c .jsdoc.js",
"predocs": "npm run compile",
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
"lint": "npm run check && eslint '**/*.js'",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"system-test": "mocha build/system-test --timeout 600000",
Expand Down Expand Up @@ -59,7 +58,6 @@
"teeny-request": "^3.4.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.2.0",
"@types/extend": "^3.0.0",
"@types/is": "0.0.21",
"@types/mocha": "^5.2.4",
Expand Down
Loading

0 comments on commit 299e5b6

Please sign in to comment.