Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: translation is not loadable when app opened by Deeplink #20

Open
hohoaisan opened this issue Dec 22, 2023 · 3 comments
Open

Error: translation is not loadable when app opened by Deeplink #20

hohoaisan opened this issue Dec 22, 2023 · 3 comments

Comments

@hohoaisan
Copy link

hohoaisan commented Dec 22, 2023

This is debug log when I open the Electron app by executing via shortcut (mainBindings function)

[2023-12-22 17:52:58.576] [info]  🚀🚀🚀 read { filename: './resources/assets/locales/en-US.json' }
[2023-12-22 17:52:58.578] [info]  🚀🚀🚀 read { filename: './resources/assets/locales/en.json' }
[2023-12-22 17:52:58.580] [info]  🚀🚀🚀 read {
  key: '1b07e6d3-a335-4871-911c-3beb7cac1ca4',
  error: "Error: ENOENT: no such file or directory, open 'C:\\Users\\[USER_NAME]\\AppData\\Local\\Programs\\vme\\resources\\assets\\locales\\en-US.json'",
  data: ''
}
[2023-12-22 17:52:58.582] [info]  🚀🚀🚀 read {
  key: 'bd20c311-3807-4329-b41e-160205d21929',
  error: null,
  data: '{\n' +
    '  "language": "Language",\n' +
    '  "ok": "OK",\n' +
    '  "login_title": "Transform to avatars.",\n' +
[THE REST OF LOADED LANGUAGE FILE]

This is debug log when I open the Electron app by using deeplink

[2023-12-22 17:54:24.215] [info]  🚀🚀🚀 read { filename: './resources/assets/locales/en-US.json' }
[2023-12-22 17:54:24.216] [info]  🚀🚀🚀 read { filename: './resources/assets/locales/en.json' }
[2023-12-22 17:54:24.216] [info]  🚀🚀🚀 read {
  key: '59f8a538-0012-4ff2-9425-7740df36d0c2',
  error: "Error: ENOENT: no such file or directory, open 'C:\\Windows\\system32\\resources\\assets\\locales\\en-US.json'",
  data: ''
}
[2023-12-22 17:54:24.218] [info]  🚀🚀🚀 read {
  key: '4a83e727-27b0-49f6-b8fa-b8ad6f3d7fe3',
  error: "Error: ENOENT: no such file or directory, open 'C:\\Windows\\system32\\resources\\assets\\locales\\en.json'",
  data: ''
}
[2023-12-22 17:54:24.475] [error] Error: HttpError: 404 

The resource was miss calculated to C:\\Windows\\system32\\ when using deeplink, is there any possible workaround/fix?

i18n config:

const loadPath = './resources/assets/locales/{{lng}}.json';

i18n
  .use(i18nBackend)
  .use(initReactI18next)
  .use(LanguageDetector)
  .init({
    backend: {
      loadPath,
      contextBridgeApiKey: 'api', // needs to match first parameter of contextBridge.exposeInMainWorld in preload file; defaults to "api"
    },
    debug: false,
    fallbackLng: 'en',
    interpolation: {
      escapeValue: false, // react already safes from xss
    },
  });
@sparrow58
Copy link

I have the same problem... did you come up to a solution @hohoaisan

It happens whenever I open the app using another app

@hohoaisan
Copy link
Author

@sparrow58 I couldn't access to the source code right now but the problem is due to fs module is not loaded to correct directory

Solution is finding the correct parent folder of ./resources/assets/locales/en-US.json (by accessing assets variable in ENV? I couldn't recall), then fake a "fs" instance in the main process, change its working directory to that folder, then pass it directly to i18next-electron-fs-backend, so that it can load correct folder instead of C:\\Windows\\system32\\

@sparrow58
Copy link

sparrow58 commented Dec 10, 2024

@hohoaisan I just found the solution, now my problem is fixed!

Add this to the beginning of your app
`const appPath = path.dirname(process.execPath)

process.chdir(appPath) // fix localization on deeplink
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants