# generaltranslation: General Translation Core SDK: GT Constructor URL: https://generaltranslation.com/en-GB/docs/core/class/constructor.mdx --- title: GT Constructor description: API reference for the GT class constructor --- ## Overview The `GT` constructor creates a new instance of the General Translation class, which provides access to all translation, formatting and locale functionality. ```typescript import { GT } from 'generaltranslation'; const gt = new GT({ apiKey: 'your-api-key', projectId: 'your-project-id', sourceLocale: 'en', targetLocale: 'es' }); ``` The constructor automatically checks the environment for the `GT_API_KEY`, `GT_DEV_API_KEY`, and `GT_PROJECT_ID` environment variables, so you can omit them from the constructor parameters. It also validates all provided locale codes. *** ## Reference ### Parameters The `GTConstructorParams` object supports the following properties: | Property | Type | Optional | Description | | --------------- | --------------- | -------- | ----------------------------------------------------- | | `apiKey` | `string` | ✓ | Production API key for the translation service | | `devApiKey` | `string` | ✓ | Development API key (takes precedence in development) | | `projectId` | `string` | ✓ | Unique project identifier | | `sourceLocale` | `string` | ✓ | Default source locale for translations | | `targetLocale` | `string` | ✓ | Default target locale for translations | | `locales` | `string[]` | ✓ | Array of supported locale codes | | `baseUrl` | `string` | ✓ | Custom API base URL (for enterprise deployments) | | `customMapping` | `CustomMapping` | ✓ | Custom locale code mappings and definitions | ### Returns A new `GT` class instance with all translation and locale methods available. *** ## Examples ### Basic usage ```typescript import { GT } from 'generaltranslation'; // Minimal setup - uses environment variables const gt = new GT(); ``` ### With API credentials ```typescript const gt = new GT({ projectId: 'my-project-id', apiKey: 'my-api-key', targetLocale: 'fr' }); ``` ### With custom locale mapping You can provide a custom mapping. This lets users (1) use aliases for locale codes, (2) override the standard BCP 47 validation, and (3) override the standard BCP 47 locale information. For example, if you wanted to use `cn` as an alias for `zh`. Because the General Translation API does not support `cn`, you must specify a custom mapping. ```typescript const gt = new GT({ projectId: 'my-project-id', apiKey: 'my-api-key', targetLocale: 'es', customMapping: { 'cn': { code: 'zh' } } }); ``` You can do other things with custom mappings, such as adding custom names, emojis and so on. ```typescript const gt = new GT({ projectId: 'my-project-id', apiKey: 'my-api-key', targetLocale: 'es', customMapping: { 'en-US': { name: 'Mandarin', emoji: '🇫🇷' } } }); ``` *** ## Notes * All parameters are optional, but API operations will require `apiKey` and `projectId` * The constructor validates all locale codes immediately and throws errors for invalid codes * Custom mappings take precedence over standard BCP 47 validation ## Next steps * Configure your instance with [`setConfig`](/docs/core/class/set-config) * Start translating with [`translate`](/docs/core/class/methods/translation/translate) * Learn about [`GTConstructorParams` type](/docs/core/types/gt-constructor-params)