# sanity-plugin-google-translate-aadgrant

> Translate your content with Google Translate directly from your Sanity Studio!

Latest version **2.0.1** (published 2022-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install sanity-plugin-google-translate-aadgrant
pnpm add sanity-plugin-google-translate-aadgrant
yarn add sanity-plugin-google-translate-aadgrant
bun add sanity-plugin-google-translate-aadgrant
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-07-19 |
| First published | 2022-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 50.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sanity.io |
| Maintainers | aadgrant |
| Keywords | sanity, sanity-plugin |

## Links

- npm: https://www.npmjs.com/package/sanity-plugin-google-translate-aadgrant
- Repository: https://github.com/sanity-io/sanity-plugin-google-translate
- Homepage: https://github.com/sanity-io/sanity-plugin-google-translate#readme
- Issues: https://github.com/sanity-io/sanity-plugin-google-translate/issues
- npm.io page: https://npm.io/package/sanity-plugin-google-translate-aadgrant

## Dependencies (6)

- [husky](https://npm.io/package/husky.md) ^7.0.1
- [@sanity/ui](https://npm.io/package/@sanity/ui.md) ^0.37.2
- [prop-types](https://npm.io/package/prop-types.md) ^15.8.1
- [@sanity/base](https://npm.io/package/@sanity/base.md) ^2.23.2
- [@sanity/form-builder](https://npm.io/package/@sanity/form-builder.md) ^2.23.2
- [@nrk/sanity-plugin-nrkno-odd-utils](https://npm.io/package/@nrk/sanity-plugin-nrkno-odd-utils.md) ^1.0.3

## Recent versions

- 2.0.1 (latest) — 2022-07-19

## README

# sanity-plugin-google-translate

This plugin lets you connect Sanity fields to Google Cloud Translate API, giving you instant machine translations for 108 languages and counting! Enable it for all of them! ...or just the ones you need.

https://user-images.githubusercontent.com/9684022/158199868-5426b7dd-8439-406f-bf16-661c4bf060a0.mov

## Installation

```
sanity install google-translate
```

## Configuration

The Google Translate plugin is designed to work with [field-level translated objects](https://www.sanity.io/docs/localization#cd568b11a09c) as a Custom Input Component to add a superset of features – automated machine translation.

These objects should be registered in the way recommended by the [@sanity/language-filter plugin](https://www.npmjs.com/package/@sanity/language-filter).

Adding the Translation buttons requires adding an `inputComponent` and API key to the object's schema. See this example of a localized string object below.

Note: This will not translate Portable Text content, as that schema type should not be mapped over multiple times in a single document. If you need multiple languages of Portable Text, you are best to use [document-level translation](https://github.com/sanity-io/document-internationalization).

### Example: Add Google Translate to all localized `string` objects

```js
import GoogleTranslateInput from 'sanity-plugin-google-translate'

const languages = [
  {id: 'en', title: 'English', isDefault: true},
  {id: 'es', title: 'Spanish'},
  {id: 'fr', title: 'French'},
]

export default {
  name: 'localizedString',
  type: 'object',
  // 👇 👇 👇
  // See: https://www.sanity.io/docs/custom-input-widgets
  inputComponent: GoogleTranslateInput,
  options: {
    // This API key will be bundled with your studio
    // and so should be restricted by hostname
    // See: https://www.sanity.io/docs/studio-environment-variables
    apiKey: process.env.SANITY_STUDIO_GOOGLE_TRANSLATE_API_KEY,
  },
  // 👆 👆 👆
  fieldsets: [
    {
      title: 'Translations',
      name: 'translations',
      options: {collapsible: true, collapsed: false},
    },
  ],
  fields: languages.map((lang) => ({
    name: lang.id,
    title: lang.title,
    type: 'string', // or `text`, etc
    fieldset: lang.isDefault ? null : 'translations',
  })),
}
```

### Example: Extend some localized `string` objects with Google Translate

Alternatively, you could selectively extend specific uses of `localizedString`, by registering another object to your schema which uses it as a base. This is helpful if you only need Google Translate on specific fields.

```js
import GoogleTranslateInput from 'sanity-plugin-google-translate'

export default {
  name: 'localizedGoogleTranslateString',
  title: 'Localized String',
  type: 'localizedString',
  inputComponent: GoogleTranslateInput,
  options: {
    apiKey: process.env.SANITY_STUDIO_GOOGLE_TRANSLATE_API_KEY,
  },
}
```

## API Key security

By including your Google Cloud Translation API key in the schema definition it becomes part of the Studio bundle which is hosted as static files on webservers.

To avoid others using your key you should restrict it to hosts where your studio runs, like

- `http://localhost:3333/*`
- `http://<your-project>.sanity.studio/*`
- ...or custom domain you may be hosting the Studio

[More info on adding HTTP restrictions](https://cloud.google.com/docs/authentication/api-keys#adding_http_restrictions)

---
_Source: https://npm.io/package/sanity-plugin-google-translate-aadgrant · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
