# generaltranslation: General Translation Core SDK: determineLocale URL: https://generaltranslation.com/en-GB/docs/core/class/methods/locales/determine-locale.mdx --- title: determineLocale description: API reference for the GT determineLocale method --- ## Overview The `determineLocale` method determines the best matching locale from a list of approved locales based on user preferences. It implements locale negotiation to find the most suitable locale when exact matches aren't available. ```typescript const gt = new GT({ sourceLocale: 'en-US', locales: ['en-US', 'es-ES', 'fr-FR', 'de-DE'] }); // Exact match console.log(gt.determineLocale('en-US')); // 'en-US' // Language fallback console.log(gt.determineLocale('en-GB')); // 'en-US' (closest English variant) // Multiple preferences console.log(gt.determineLocale(['fr-CA', 'es-MX', 'en-US'])); // 'es-ES' (closest Spanish) // No match console.log(gt.determineLocale('it-IT')); // undefined ``` *** ## Reference ### Parameters ### Returns `string | undefined` - Best matching locale, or undefined if no match is found *** ## Examples ### User locale negotiation ```typescript const gt = new GT({ sourceLocale: 'en-US', locales: ['en-US', 'en-GB', 'es-ES', 'fr-FR'] }); // Simulate browser Accept-Language header const userPreferences = ['fr-CA', 'en-GB', 'en']; const bestMatch = gt.determineLocale(userPreferences); console.log(bestMatch); // 'fr-FR' based on preference order ``` *** ## Notes * Returns the first exact match from approved locales * Falls back to language matches when an exact region isn't available * Respects the preference order in the input array * Returns undefined when no suitable match is found * Essential for implementing locale negotiation in web applications ## Next steps * Check translation needs with [`requires-translation`](/docs/core/class/methods/locales/requires-translation) * Compare languages with [`is-same-language`](/docs/core/class/methods/locales/is-same-language)