GT Class

setConfig

API Reference for the GT setConfig method

Overview

The setConfig method updates the configuration of an existing GT instance. This allows you to modify API credentials, locales, and other settings after the instance has been created.

const gt = new GT();

gt.setConfig({
  apiKey: 'your-new-api-key',
  projectId: 'your-project-id',
  sourceLocale: 'en',
  targetLocale: 'es'
});

The setConfig method will validate all provided locale codes and merge with any existing configuration that was passed to the constructor.


Reference

Parameters

Prop

Type

The GTConstructorParams object supports the same properties as the constructor:

PropertyTypeOptionalDescription
apiKeystringProduction API key for translation service
devApiKeystringDevelopment API key
projectIdstringUnique project identifier
sourceLocalestringDefault source locale for translations
targetLocalestringDefault target locale for translations
localesstring[]Array of supported locale codes
baseUrlstringCustom API base URL
customMappingCustomMappingCustom locale code mappings

Returns

void - The method updates the instance configuration in-place.


Example

In this example, we switch the target locale from Spanish to French.

const gt = new GT({
  sourceLocale: 'en',
  targetLocale: 'es'
});

// Switch to French
gt.setConfig({
  targetLocale: 'fr'
});

Notes

  • Configuration changes take effect immediately for subsequent method calls
  • Environment variables are not re-read when calling setConfig
  • Custom mappings completely replace existing mappings (not merged)
  • Validation failures leave the instance configuration unchanged
  • The method is synchronous and returns void

Next Steps

How is this guide?

setConfig