sveltekit-i18n / lib

Internationalization library built for SvelteKit.
MIT License
491 stars 32 forks source link

How to insert variables into translation #107

Closed Antoine-lb closed 1 year ago

Antoine-lb commented 1 year ago

Hello 👋 I could not find in the documentation how to insert variables inside of a translation string (e.g. you have {{notification_count}} notifications). Is this functionality not supported or I just can't find it?

An example of react-i18next approach of it: https://react.i18next.com/latest/trans-component#using-with-react-components

Thanks for your time

akiarostami commented 1 year ago

In the resource file use {{ }} for the variable (as you have mentioned here):

"notification": "you have {{notification_count}} notifications"

To call it, use the variable passed as a parameter:

$t('notification', { notification_count: 5 })