# General Translation Platform: standardizeLocale URL: https://generaltranslation.com/en-GB/docs/platform/core/reference/utility-functions/locales/standardize-locale.mdx --- title: standardizeLocale description: Normalise a locale code into a standard format without a GT instance. API reference for standardizeLocale. --- [`standardizeLocale`](/docs/platform/core/reference/gt-class-methods/locales/standardize-locale) is a standalone utility function from General Translation's Core library that normalises a BCP-47 locale code into its canonical form, correcting casing. ## Overview [#overview] Import `standardizeLocale` directly from `generaltranslation` and call it with a locale code. It does not require an API key or a [GT](/docs/platform/core/reference/gt-class/constructor) instance. For the instance-based equivalent, use the [`standardizeLocale`](/docs/platform/core/reference/gt-class-methods/locales/standardize-locale) method on a [`GT`](/docs/platform/core/reference/gt-class/constructor) instance instead. ```typescript import { standardizeLocale } from 'generaltranslation'; // Normalise casing console.log(standardizeLocale('EN-gb')); // 'en-GB' console.log(standardizeLocale('fr-ca')); // 'fr-CA' // Already standardised locales pass through console.log(standardizeLocale('es-ES')); // 'es-ES' ``` Signature: ```typescript standardizeLocale(locale: string): string ``` ## How it works [#how-it-works] * **Canonicalisation.** Passes the input to `Intl.getCanonicalLocales` and returns the first canonical result, which normalises casing (language lowercase, region uppercase, script title case). * **Fallback.** If the input cannot be canonicalised, the original input string is returned unchanged. ## Parameters [#parameters] | Parameter | Description | Type | Optional | Default | | ------------------- | -------------------------------------- | -------- | -------- | ------- | | [`locale`](#locale) | The BCP-47 locale code to standardise. | `string` | No | — | ### `locale` [#locale] **Type** `string` · **Required** The BCP-47 locale code to standardise. ## Returns [#returns] **Type** `string` The standardised BCP-47 locale code, or the input string unchanged if it cannot be standardised. ## Examples [#examples] ```typescript import { standardizeLocale } from 'generaltranslation'; // Normalises casing on hyphenated tags console.log(standardizeLocale('EN-gb')); // 'en-GB' console.log(standardizeLocale('fr-ca')); // 'fr-CA' console.log(standardizeLocale('en-us')); // 'en-US' // Already standardised locales pass through console.log(standardizeLocale('es-ES')); // 'es-ES' // Non-canonicalisable input is returned unchanged console.log(standardizeLocale('en_us')); // 'en_us' (underscore is not valid BCP-47) console.log(standardizeLocale('not a locale')); // 'not a locale' ``` ```typescript import { standardizeLocale, isValidLocale } from 'generaltranslation'; // Normalising user input function processUserInput(input: string) { const standardized = standardizeLocale(input.trim()); const isValid = isValidLocale(standardized); return { original: input, standardized, isValid, }; } // Test various inputs const inputs = ['EN-gb', 'FR-ca', 'invalid', 'zh-CN']; inputs.forEach((input) => { console.log(processUserInput(input)); }); ``` ## Notes [#notes] * Normalises casing (language lowercase, region uppercase) via `Intl.getCanonicalLocales`. * Returns the input string unchanged for inputs that cannot be canonicalised. * Essential for normalising locale input from various sources. * No external dependencies beyond the `Intl` API.