cyrilwanner / next-optimized-images

🌅 next-optimized-images automatically optimizes images used in next.js projects (jpeg, png, svg, webp and gif).
MIT License
2.21k stars 93 forks source link

Import of images using the path from localization files #218

Closed Svyatoslav16 closed 3 years ago

Svyatoslav16 commented 3 years ago

I'm tried require image with locale file in json RU file with locales

{
    "connect-all-data-sources-image": "connect-all-data-sources-ru.jpg",
}

EN file with locales

{
    "connect-all-data-sources-image": "connect-all-data-sources-en.jpg",
}

/pages/index.jsx

import React from 'react';
import Img from 'react-optimized-image';
import useTranslation from 'next-translate/useTranslation';
const Index = () => {
     const { t } = useTranslation();
     return (
         <div>
             <Img src={require(`../public/images/${t('common:connect-all-data-sources-image')}`)} />
         </div>
     )
}

but i get some errors:

(node:21318) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 uncaughtException listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
(node:21318) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added to [process]. Use emitter.setMaxListeners() to increase limit

Is it possible to use this package to optimize images with the localization package? If yes, tell me another way, what I am doing wrong, but if not, I would like to understand the reason, because this is what communities of programmers are for.

Thank you in advance for answering