API keys
How to use API keys with General Translation
Overview
There are two types of API keys used with General Translation:
- Production API Key: Used to translate your content in production.
- Development API Key: Used to translate your content in development.
The behaviour of the two key types differs, so take care to use the correct key for your environment.
GT_PROJECT_ID=your-project-id
GT_API_KEY=your-api-keyIf you’re using gt-next or gt-react as a standalone i18n library, you don’t need to use API keys.
How to obtain
Go to your project dashboard on the General Translation website.
Click the “API Keys” or “Developer Keys” tab.
Click the “Create API Key” button.
Copy the API key and paste it into your project’s .env file.
Behaviour
Put simply, Prod API keys persist translations, whereas Dev API keys do not. Use Dev API keys for prototyping translations, and Prod API keys when you’re ready to deploy.
Development API Key
This type of key is useful for testing and development purposes. When using a development API key, translations are performed on demand and memoised in memory. Translations will not be saved.
The development API key is used by components rendered in the browser (client-side) and by server-side rendered components to facilitate on-demand translation. This means it must be exposed to the client. This key should NEVER be used in production environments and should NEVER be sent to the client in a production environment.
# example Vite .env file for dev
VITE_GT_PROJECT_ID=your-project-id
VITE_GT_API_KEY=your-dev-api-key # Only used in developmentWarning: Development API keys are passed to the client to enable client-side translation during development. This is fine in development environments, but it is a security risk in production. If your application is accessible on the internet, you should never use a development API key.
Production API Key
When using a production API key, translations are persisted. This means translations will be saved (either on a CDN or in your app’s bundle) to be used at runtime.
This key is used in two places:
- The
gtx-clitool. See the docs for more information. - The
gt-nextlibrary when translations occur at runtime in a production build (server-side only; not used bygt-react).
The API key is only used by the server, and it should NEVER be exposed to the client.
GT_PROJECT_ID=your-project-id
GT_API_KEY=your-prod-api-key # This key should never be exported to the clientNotes
- Development API keys are for testing and development only. They should only be used in development.
- Production API keys are for use in production.
Next steps
- See how to use the
<T>component to preview live translations during development.
How is this guide?