0.0.4 • Published 3 years ago

@scandinavia/use-inner-translation v0.0.4

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

Scandinavia

use-inner-translation

this package help you to use a translation by pasing locale to it. usefull:

  1. when you need translation in a small component and you dont want to use the default i18next-react.
  2. 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'.
        // ...
    )

}