1.0.2 • Published 5 years ago
estafette-intl v1.0.2
Installation
With yarn:
yarn add estafette-intlWith npm:
npm install estafette-intlGetting started
Steps:
- Create internalization
- Create messages
- Use internalization using useIntl
Create internalization
import { CreateIntl } from 'estafette-intl';
ReactDOM.render(
<CreateIntl defaultLocale="en" messages={messages}>
<App />
</CreateIntl>,
document.getElementById('root'),
);Create messages
import { createMessages } from 'estafette-intl';
const messages = createMessages([
{
gretting: {
en: 'Hello, {name}!',
},
},
]);Use internalization using useIntl
import { useIntl } from 'estafette-intl';
const App = () => {
const { t } = useIntl();
return <h1>{t('gretting', { name: 'Vladimir Josan' })}</h1>;
};API
CreateIntl
Internalization creator
Props
defaultLocale(String) - it can be simple string, that you will be able to change fromuseIntlusingsetLocalemessages(Object) -MessagesfromcreateMessage
createMessage
function helper, gets array of messages, parses all of them into an object and checks for dublicates
Arguments
messages(Array) -Messages
Messages
typescript interface
Interface
interface Messages {
[locale: string]: {
[lang: string]: string;
};
}useIntl
hook helper for using internalization
Returns
t(Function) - a function that requireslocale(String) argument and returns bylocalekeyword necessary textlocale(String) - current localesetLocale(Function) - a function that requiresnewLocale(String) argument and change current locale to the new locale.