General Translation  
React

Helper hooks

useLocale()

useLocale() retrieves the user's current language as an ISO-639 language code. It can be used in the descendants of <GTProvider>.

import { useLocale } from 'gt-react'
 
export default function MyComponent() {
    const locale = useLocale(); // e.g. 'en-US'
    return (
        <div>
            {locale}
        </div>
    )
}

useDefaultLocale()

The application's default locale can be accessed in the descendants of <GTProvider> with the useDefaultLocale() hook.

import { useDefaultLocale } from 'gt-react'
 
export default function MyComponent() {
    const defaultLocale = useDefaultLocale(); // e.g. 'en-US'
    return (
        <div>
            {defaultLocale}
        </div>
    )
}

On this page