I18nPro react is a React helper that provides functionalities for internationalization (i18n). It uses the i18nPro
library for the actual i18n operations.
npm install @marchintosh94/i18n-pro-react
# or
yarn add @marchintosh94/i18n-pro-react
-
defaultLocale
(string): The default language to use if no language is specified.
Import the i18nPro module and set your desired configuration in the entry point of your application:
// src/index.ts
import { i18nPro } from '@marchintosh94/i18n-pro-react'
i18nPro.defaultLocale = 'en-US'
//... other
This is the main library that implements all core functionalities uesd by i18nPro React. Read more about core functionalities and how to use it
useI18nPro
is a custom React hook that provides functionalities for internationalization (i18n).
The hook returns an object with the following properties:
-
locale
: The current locale. -
t
: A function to translate a given key into the current locale. -
switchLoadLanguage
: A function to change the current language and load the new translations. -
updateExisitngLocale
: A function to update the current locale if it's available in thei18nPro
library.
Translates a given key into the current locale.
-
value
: The key to translate. -
...args
: The arguments to pass to thei18nPro.t
function.
The translated string.
Changes the current language and loads the new translations.
-
...args
: The arguments to pass to thei18nPro.changeLanguage
function.
A promise that resolves to the updated locale.
Updates the current locale if it's available in the i18nPro
library.
-
locale
: The locale to set.
The updated locale, or an empty string if the locale was not updated.
withI18nPro
is a higher-order component (HOC) that enhances a component with i18nPro
functionality. It uses the useI18nPro
hook to provide internationalization (i18n) capabilities to the wrapped component.
-
WrappedComponent
: The component to be wrapped. This component will receive all the props of the original component, along with the additional props provided by theuseI18nPro
hook.
The HOC returns a new component that renders the WrappedComponent
with the additional i18nPro
props. The returned component accepts all the props of the WrappedComponent
, except for the props provided by the useI18nPro
hook.
This project is licensed under the MIT License.