getDefaultTranslationLocale
See source codeGets the default translation locale based on the user's browser language preferences.
This function determines the best matching locale from the user's browser language settings, falling back to English if no suitable match is found. It works in both browser and server-side environments, defaulting to English on the server.
The function prioritizes exact matches first, then falls back to language-only matches, and finally uses predefined regional defaults for languages like Chinese, Portuguese, Korean, and Hindi.
function getDefaultTranslationLocale(): TLLanguage['locale']
Example
import { getDefaultTranslationLocale } from '@tldraw/tlschema'
// Get the user's preferred locale
const locale = getDefaultTranslationLocale()
console.log(locale) // e.g., "fr" or "en" or "zh-cn"
// Use in localization setup
const i18n = new I18n({
locale,
// ... other config
})
// Browser with languages: ['fr-CA', 'en-US']
const locale = getDefaultTranslationLocale()
console.log(locale) // "fr" (if French is supported)
// Browser with languages: ['zh']
const locale = getDefaultTranslationLocale()
console.log(locale) // "zh-cn" (default region for Chinese)
Prev
getDefaultColorThemeNext
getDefaultUserPresence