1
1
12332112021-05-25 12:43:08
React
1233211, 2021-05-25 12:43:08

How to make such import of files?

I want to import locales like this:
import { en, ru } from 'public/locales';
what is the right way to do this?
now I have the following structure (example for 'en')

public/locales/en.js

внутри en.js:

export const main = {...}
export const nav = {...}
export const footer = {...}
...


Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Ivanovich, 2021-05-25
@1233211

1. Create index.js in public/locales
2. In index.js import the required locales

import en from 'path/to/en';
import ru from 'path/to/ru';

3. Export as an object
export {
    en,
    ru,
}

4. Done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question