0.0.4 • Published 3 years ago
@scandinavia/use-inner-translation v0.0.4
Scandinavia
use-inner-translation
this package help you to use a translation by pasing locale to it. usefull:
- when you need translation in a small component and you dont want to use the default
i18next-react
. - you want to make his translation in his files.
usage
first you need to create the local file,locale.ts
export default {
en: {
submit: 'Submit',
// ...rest
},
ar: {
submit: 'إرسال',
// ...rest
},
};
then you can use the hook useInnerTranslation
to get the translation inside you component file component.tsx
.
// ...imports
import { useInnerTranslation } from '@scandinavia/use-inner-translation';
import locale from './locale';
export const Component: React.FC = ()=>{
// ...
const { t, lang } = useInnerTranslation(locale);
// ...
return (
// ...
{t('submit')} // return 'Submit' when language is 'en' or 'إرسال' when language is 'ar'.
// ...
)
}