gt-react-native
v11.0.3
Published
An i18n package for React Native
Readme
gt-react-native
Automatic i18n for React Native.
Installation
npm install gt-react-native
npm install gt --save-devQuick Start
npx gt init// index.ts
import { registerRootComponent } from 'expo';
import { initializeGT } from 'gt-react-native';
import App from './App';
import gtConfig from './gt.config.json';
import esTranslations from './src/_gt/es.json';
import frTranslations from './src/_gt/fr.json';
const localTranslations = {
es: esTranslations,
fr: frTranslations,
};
initializeGT({
defaultLocale: gtConfig.defaultLocale,
locales: gtConfig.locales,
loadTranslations: async (locale) => localTranslations[locale] ?? {},
});
registerRootComponent(App);// App.tsx
import { Text } from 'react-native';
import { T, GTProvider } from 'gt-react-native';
export default function App() {
return (
<GTProvider>
<T>
<Text>This gets translated automatically.</Text>
</T>
</GTProvider>
);
}See the full documentation for guides and API reference.
