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: This is used to translate your content in production.
- Development API Key: This is used to translate your content in development.
The behavior between the two types of keys are different, so you should be careful to use the correct key for the environment you are in.
If you are using gt-next
or gt-react
as a standalone i18n library, you do not need to use API keys.
How to obtain
Navigate to your project dashboard on the General Translation website.
Click on the "API Keys" or "Developer Keys" tab.
Click on the "Create API Key" button.
Copy the API key and paste it into your project's .env
file.
Behavior
Most simply put, Prod API keys persist translations, while Dev API keys do not. You use Dev API keys for prototyping translations and Prod API keys when you are 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 done on-demand and memoized 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 that it must be exported to the client. This key should NEVER be used in production environments and NEVER should be passed to the client in a production environment.
Warning: Development API keys are passed to the client to facilitate client-side translation in development. This is fine in development environments, but is a security risk in production environments. If your application is open to the internet, you should never use a development API key.
Production API Key
When using a production API key, translations are persisted. This means that translations will be saved (either in a CDN or in your app's bundle) to be used at runtime.
This key is used in two places:
- The
gtx-cli
tool. Check out this guide for more information. - The
gt-next
library 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 exported to the client.
Notes
- Development API keys are used for testing and development purposes. It should only be used in development.
- Production API keys are used for production purposes.
Next steps
- Check out how to use the
<T>
component to see live translations in development. - See the usage guide for the cli tool.