cyrilwanner / next-optimized-images

🌅 next-optimized-images automatically optimizes images used in next.js projects (jpeg, png, svg, webp and gif).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Import of images using the path from localization files

Svyatoslav16 opened this issue · comments

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