# gt-react: General Translation React SDK: Overview URL: https://generaltranslation.com/en-US/docs/react/introduction.mdx --- title: Overview description: Overview of General Translation's React SDK --- {/* AUTO-GENERATED: Do not edit directly. Edit the template in content/docs-templates/ instead. */} ## Introduction The General Translation React SDK is an open-source internationalization (i18n) library for React applications. It provides a comprehensive set of tools to internationalize your React application in an easy and maintainable way, with feature parity to other popular i18n libraries. The SDK can be used standalone without the General Translation platform and behaves similarly to other i18n libraries. However, it also integrates with our platform for enhanced features: - Translation hot reloading in development - Automatic AI translations - Syncing translations with the General Translation platform - Native integration with our translation CDN ## Concepts There are 5 main concepts to understand about the SDK. The [``](/docs/react/api/components/gtprovider) component The [``](/docs/react/api/components/t) component The [`useGT`](/docs/react/api/strings/use-gt) hook The [`msg`](/docs/react/api/strings/msg) function for shared strings (Optional) The [`useTranslations`](/docs/react/api/dictionary/use-translations) hook ## The `` component The [``](/docs/react/api/components/gtprovider) component provides translation context to your application, including the current language and relevant translations. ```tsx import { GTProvider } from 'gt-react'; function App() { return (
{/* Your application content */}
); } ``` **Important:** The provider should wrap your entire application and be placed as high in the component tree as possible, such as in your root App component. See the [`GTProvider`](/docs/react/api/components/gtprovider) API reference for more information. ## The `` component The [``](/docs/react/api/components/t) component is the recommended way to translate content in your application. It is a React component that can be used to wrap any JSX element, and will automatically render the content of the element into a supported language. We recommend using the [``](/docs/react/api/components/t) component wherever possible, since it allows for the most flexibility in translations. Unlike strings, the [``](/docs/react/api/components/t) component can be used to translate HTML content, making it much more powerful than string translations. ### Examples ```tsx
Hello, world!
``` ```tsx

Here is an image

Example
``` ```tsx Formatting can be done easily with the `` component. {1000} {new Date()} {1000} ``` The [``](/docs/react/api/components/t) component works with [variable components](/docs/react/guides/variables) like [``](/docs/react/api/components/num), [``](/docs/react/api/components/datetime), and [``](/docs/react/api/components/currency) for dynamic content formatting. See the [`` component guide](/docs/react/guides/t) to learn about the different ways to use the [``](/docs/react/api/components/t) component. ## The `useGT` hook The [`useGT`](/docs/react/api/strings/use-gt) hook is a React hook that can be used similarly to the [``](/docs/react/api/components/t) component, with some trade-offs. The hook returns a function that can be used to translate strings. ```tsx const gt = useGT(); gt('Hello, world!'); ``` Compared to the [``](/docs/react/api/components/t) component, the [`useGT`](/docs/react/api/strings/use-gt) hook allows for more flexibility in your codebase. For example, if you have a complex data structure with nested strings, a [``](/docs/react/api/components/t) component would be more difficult to use. ```tsx const gt = useGT(); const data = { title: gt('Hello, world!'), description: gt('This is a description'), }; ``` See the [strings](/docs/react/guides/strings) guide to learn more about the [`useGT`](/docs/react/api/strings/use-gt) hook. ## The `msg` function The [`msg`](/docs/react/api/strings/msg) function is used to mark strings for translation that are used across multiple components or stored in configuration objects. This is particularly useful for shared content like navigation labels, form messages, or any text that appears in multiple places throughout your application. ```tsx // Mark strings for translation import { msg } from 'gt-react'; const navItems = [ { label: msg('Home'), href: '/' }, { label: msg('About'), href: '/about' }, { label: msg('Contact'), href: '/contact' } ]; ``` ```tsx // Decode and use the marked strings import { useMessages } from 'gt-react'; function Navigation() { const m = useMessages(); return ( ); } ``` The [`msg`](/docs/react/api/strings/msg) function encodes strings with translation metadata, and [`useMessages`](/docs/react/api/strings/use-messages) decodes them. Use [`msg`](/docs/react/api/strings/msg) for shared content that needs to be translated consistently across your application. For component-specific content, prefer [``](/docs/react/api/components/t) or [`useGT`](/docs/react/api/strings/use-gt). See the [shared strings](/docs/react/guides/shared-strings) guide to learn more about the `msg` function. ## The `useTranslations` hook The [`useTranslations`](/docs/react/api/dictionary/use-translations) hook is a React hook that returns a function that can be used to retrieve translations for a given key. ```tsx title="dictionary.ts" const dictionary = { hello: { world: 'Hello, world!', }, }; ``` ```tsx title="App.tsx" const translate = useTranslations(); translate('hello.world'); ``` This behavior is similar to other translation libraries, such as [`react-i18next`](https://react.i18next.com/) and [`next-intl`](https://next-intl-docs.vercel.app/). We do not recommend using the [`useTranslations`](/docs/react/api/dictionary/use-translations) hook in your application. Frequent use of the [`useTranslations`](/docs/react/api/dictionary/use-translations) hook will make your codebase more difficult to maintain, and will lead to large tech debt. Instead, we recommend using the [``](/docs/react/api/components/t) component or the [`useGT`](/docs/react/api/strings/use-gt) hook. If you are migrating from another i18n library, the [`useTranslations`](/docs/react/api/dictionary/use-translations) hook is a drop-in replacement and can be useful for incrementally migrating your codebase. See the [dictionaries](/docs/react/guides/dictionaries) guide to learn more about the [`useTranslations`](/docs/react/api/dictionary/use-translations) hook. See the [useTranslations API Reference](/docs/react/api/dictionary/use-translations) for more information. --- ## Next steps - Learn about how to set up your React project with the SDK: [Quickstart](/docs/react/tutorials/quickstart) - Learn about how to translate JSX content with the [``](/docs/react/api/components/t) component: [JSX Translation Guide](/docs/react/guides/t) - Learn about how to translate strings with the [`useGT`](/docs/react/api/strings/use-gt) hook: [String Translation Guide](/docs/react/guides/strings) - Learn about shared strings with the [`msg`](/docs/react/api/strings/msg) function: [Shared Strings Guide](/docs/react/guides/shared-strings)