element-desktop icon indicating copy to clipboard operation
element-desktop copied to clipboard

Could not fetch translation json for locale: 'de'

Open Nils1729 opened this issue 7 months ago • 4 comments

Steps to reproduce

  1. Where are you starting? What can you see?
  • In Ubuntu settings, set my language to German
  • Install and launch Element Desktop
  • Log in, go to SettingsGeneralLanguage and region and select Deutsch (German)

Outcome

What did you expect?

Right-clicking the tray icon, the options are German.

What happened instead?

Right-clicking the tray icon, the options are still Show/Hide and Quit (not German). Web content is localized, though.

The logs show this error:

Changing application language to de
Fetching translation json for locale: de
Could not fetch translation json for locale: 'de' Error: Cannot find module './i18n/strings/de.json'
Require stack:
- /opt/Element/resources/app.asar/lib/language-helper.js
- /opt/Element/resources/app.asar/lib/tray.js
- /opt/Element/resources/app.asar/lib/settings.js
- /opt/Element/resources/app.asar/lib/ipc.js
- /opt/Element/resources/app.asar/lib/electron-main.js
- 
    at node:internal/modules/cjs/loader:1084:15
    at Function._resolveFilename (node:electron/js2c/browser_init:2:116646)
    at node:internal/modules/cjs/loader:929:27
    at Function._load (node:electron/js2c/asar_bundle:2:13327)
    at Module.require (node:internal/modules/cjs/loader:1150:19)
    at require (node:internal/modules/cjs/helpers:121:18)
    at AppLocalization.fetchTranslationJson (/opt/Element/resources/app.asar/lib/language-helper.js:86:20)
    at /opt/Element/resources/app.asar/lib/language-helper.js:99:39
    at Array.filter (<anonymous>)
    at AppLocalization.setAppLocale (/opt/Element/resources/app.asar/lib/language-helper.js:98:39) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/opt/Element/resources/app.asar/lib/language-helper.js',
    '/opt/Element/resources/app.asar/lib/tray.js',
    '/opt/Element/resources/app.asar/lib/settings.js',
    '/opt/Element/resources/app.asar/lib/ipc.js',
    '/opt/Element/resources/app.asar/lib/electron-main.js',
    undefined
  ]
}

So there is no de.json?

Probable cause

Digging into probable causes, I suspect the following chain of events:

  1. The language options are taken from the file names in this and this directory.
  2. Here, locales in the form xy_XY are shortened to xy. This only affects en_EN and de_DE.
  3. Element Desktop receives the locale via IPC.
  4. Here, en is hard-coded to be replaced by en_EN again. German locale is still de instead of de_DE.
  5. This probably caused no problem (as seen in successful loading of de in unrelated issues) until recently. I suspect consolidating de.json into de_DE.json caused loading of the file to fail as it was removed.

Potential fixes

  • Kind of ugly, but an additional hard-coded replacement from de to de_DE
  • Renaming de_DE.json to de.json in Element Desktop

Operating system

Ubuntu

Application version

Element version: 1.11.53 Crypto version: Olm 3.2.15

How did you install the app?

No response

Homeserver

No response

Will you send logs?

No

Nils1729 avatar Jan 09 '24 14:01 Nils1729

I am willing to provide a PR for this. I think each of these changes could resolve the issue and would like to respect a maintainer's preferernce, or a different suggestions:

  • [ ] Renaming de_DE.json to de.json
  • [ ] Adding a replacement for de to de_DE, just like it is done with enen_EN

Nils1729 avatar Jan 28 '24 14:01 Nils1729

@Nils1729 option 1 isn't an option as Localazy would just overwrite your change, 2 would work but the correct solution would be to use something like normalizeLanguageKey in matrix-web-i18n to fallback to the general language file if the country specific one is unavailable.

t3chguy avatar Jan 29 '24 09:01 t3chguy

This seems to crash the app on MacOS BigSur

luxzeitlos avatar Feb 29 '24 19:02 luxzeitlos

BigSur is EOL so is not supported - https://github.com/element-hq/element-web#supported-environments

t3chguy avatar Feb 29 '24 19:02 t3chguy

I just started experiencing this issue on OpenSUSE Tumbleweed:

No update_base_url is defined: auto update is disabled
Fetching translation json for locale: en_EN
Changing application language to de
Fetching translation json for locale: de
Could not fetch translation json for locale: 'de' Error: ENOENT: no such file or directory, open '/usr/share/element/app/lib/i18n/strings/de.json'
    at Object.readFileUtf8 (node:internal/fs/sync:25:18)
    at Object.readFileSync (node:fs:441:19)
    at t.readFileSync (node:electron/js2c/node_init:2:9771)
    at loadJsonFile (/usr/share/element/app/lib/utils.js:55:36)
    at AppLocalization.fetchTranslationJson (/usr/share/element/app/lib/language-helper.js:83:45)
    at /usr/share/element/app/lib/language-helper.js:96:39
    at Array.filter (<anonymous>)
    at AppLocalization.setAppLocale (/usr/share/element/app/lib/language-helper.js:95:39)
    at new AppLocalization (/usr/share/element/app/lib/language-helper.js:65:18)
    at /usr/share/element/app/lib/electron-main.js:530:30 {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/usr/share/element/app/lib/i18n/strings/de.json'
}
Resetting the UI components after locale change
Resetting the UI components after locale change
(node:10295) electron: Failed to load URL: vector://vector/webapp/ with error: ERR_FILE_NOT_FOUND
(Use `electron --trace-warnings ...` to show where the warning was created)
[10332:0705/120921.278141:ERROR:gl_surface_presentation_helper.cc(260)] GetVSyncParametersIfAvailable() failed for 1 times!

Version:

S  | Name            | Type    | Version     | Arch   | Repository
---+-----------------+---------+-------------+--------+----------------------
i+ | element-desktop | package | 1.11.69-2.1 | x86_64 | Main Repository (OSS)

element-desktop is looking for de.json, but de_DE.json exists:

image

I tried adjusting ~/.config/Element/electron-config.json to:

{
    "locale": [
        "de_DE"
    ]
}

(was "de" before)

This causes the above error to no longer surface, but it does not make element-desktop start fully:

image

The state in the screenshot is stable. Nothing changes afterwards.

Neither does removing ~/.config/Element/electron-config.json altogether allow element-desktop to start successfully:

image

LeoniePhiline avatar Jul 05 '24 10:07 LeoniePhiline