import path from 'path' export const findMessage = async (key: string, lang: string) => { let customPathOfArray: any = key.split('.') let customPathOfText = ''; const errorKey = customPathOfArray.at(-1); if (customPathOfArray.length < 2) { customPathOfText += '/common.js' customPathOfArray.pop(-1) customPathOfArray.push('common') } else { customPathOfArray.pop(-1) customPathOfArray.forEach((element: string) => { customPathOfText += '/' + element; }); } const languagePath = "./src/langs/" + lang + customPathOfText; const messageJson = await import(path.resolve(languagePath)) const messageText = await messageJson[customPathOfArray[0]][errorKey]; return messageText; }