EugeneMeles / laravel-react-i18n

Allows to connect your `Laravel` Framework translation files with `React`.
MIT License
75 stars 9 forks source link

Unable to place link in placeholder #18

Closed hogekai closed 10 months ago

hogekai commented 10 months ago

This package is great, but I can't place the link.

example:

t("I agree to the :terms_of_service and :privacy_policy", {
    terms_of_service: <Link href={route('terms.show')}>{t('Terms of Service')}</Link>, // type error
    privacy_policy: `<a href="${route('policy.show')}">${t('Privacy Policy')}</a>`, // Not recognized as HTML
})

Is there a way? thanks.

EugeneMeles commented 10 months ago

You can try insert this at warpper component to 'dangerouslySetInnerHTML' prop. like this:

<div
   dangerouslySetInnerHTML={{__html: t("I agree to the :terms_of_service and :privacy_policy", {
      terms_of_service: `<a href="${route('terms.show')}">${t('Terms of Service')}</a>`,
      privacy_policy: `<a href="${route('policy.show')}">${t('Privacy Policy')}</a>`,
   })
}}
/>
hogekai commented 10 months ago

It worked as expected. Thank you!