Google Cloud Translation
Enterprise-grade Neural Machine Translation using Google Cloud Translation API.
Google Cloud Translation provides enterprise-grade Neural Machine Translation (NMT) with support for 100+ languages.
Installation
pnpm add @google-cloud/translateAuthentication
Set up authentication using one of these methods:
Option 1: Service Account Key File
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"Option 2: Pass credentials directly
const translator = createGoogleCloudTranslator({
credentials: {
client_email: process.env.GOOGLE_CLIENT_EMAIL,
private_key: process.env.GOOGLE_PRIVATE_KEY
},
projectId: process.env.GOOGLE_PROJECT_ID
})Usage
import { defineConfig, createGoogleCloudTranslator } from '@terai/dev'
const translator = createGoogleCloudTranslator({
projectId: process.env.GOOGLE_PROJECT_ID
})
export default defineConfig({
projectLocale: 'en-US',
outLocales: ['es-ES', 'fr-FR', 'de-DE'],
outDir: './locale',
translator
})Options
All options from @google-cloud/translate are supported:
| Option | Type | Description |
|---|---|---|
projectId | string | Your Google Cloud project ID |
credentials | object | Service account credentials |
keyFilename | string | Path to service account key file |
Features
- Neural Machine Translation: High-quality translations using Google's NMT models
- 100+ Languages: Support for a wide range of language pairs
- Auto-detection: Can automatically detect source language
- Enterprise SLA: Reliable service with enterprise support
- Pay-per-character: Cost-effective pricing based on usage
Setup Guide
- Create a Google Cloud project at console.cloud.google.com
- Enable the Cloud Translation API
- Create a service account and download the JSON key
- Set the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable
Example with Environment Variables
import { defineConfig, createGoogleCloudTranslator } from '@terai/dev'
const translator = createGoogleCloudTranslator({
projectId: process.env.GOOGLE_PROJECT_ID,
credentials: {
client_email: process.env.GOOGLE_CLIENT_EMAIL,
private_key: process.env.GOOGLE_PRIVATE_KEY?.replace(/\\n/g, '\n')
}
})
export default defineConfig({
projectLocale: 'en-US',
outLocales: ['es-ES', 'fr-FR', 'ja-JP', 'zh-CN'],
outDir: './locale',
translator
})