Skip to main content

useTranslator

Sometimes you need ability to render some strings not as components. For example, placeholder of input. In this cases useTranslator might be very helpful. That hook returns instance of class Translator.

const translator = useTranslator(); // use default language
const translator = useTranslator('fr'); // use other language

React / Preact#

import { useTranslator } from '@eo-locale/react';
export function SomeComponent() {
const translator = useTranslator();
return <input placeholder={translator.formatNumber(1000)} />;
}

React Native#

import {TextInput} from 'react-native';
import {useTranslator} from '@eo-locale/react-native';
export function SomeComponent() {
const translator = useTranslator();
return (
<TextInput
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
value={translator.formatNumber(1000)}
/>
);
}