element-hq / element-desktop

A glossy Matrix collaboration client for desktop.
https://element.io
GNU Affero General Public License v3.0
1.15k stars 262 forks source link

Element desktop does not have an en_US translation #871

Closed novocaine closed 1 year ago

novocaine commented 3 years ago

Steps to reproduce

Settings -> General -> Language and Region -> select English (US)

What happened?

Doing this causes the language to be set both in matrix-react-sdk (to translate the webapp) and in element-desktop (to translate the os menus etc).

matrix-react-sdk has en_US translations, but Element desktop doesn't. This causes the electron layer to write an error to its log and fall back to plain en (I guess this is UK?). The log looks something like https://gist.github.com/monochromec/14ce9a604a368d0ee017730923ab9265 - this is more visible on linux where the log appears on stderr, I'm not sure where it appears on other platforms.

This isn't a fatal issue but it does appear loudly in the stderr of every en_US Element user on Linux (or any platform where the users tend to see stderr) so it is a red herring in almost every bug report on linux.

Operating system

Any, but most visible on Linux

Application version

1.9.0

How did you install the app?

Nightly

Homeserver

matrix.org

Have you submitted a rageshake?

No

novocaine commented 3 years ago

Examples of defects where this is obscuring the root cause

https://github.com/vector-im/element-web/issues/18038 https://github.com/vector-im/element-web/issues/18189 https://github.com/vector-im/element-web/issues/19153 https://github.com/vector-im/element-web/issues/19169 https://github.com/vector-im/element-desktop/issues/863 https://github.com/vector-im/element-web/issues/18509

novocaine commented 2 years ago

Fixed in https://github.com/vector-im/element-desktop/pull/275

acxz commented 2 years ago

@novocaine I believe this issue is not completely resolved. While element does have the en_US translation. It does not seem to load it in. This is true for other **_** translations like pt_BR as well.

In the matrix-react-sdk code the following __mocks__/languages.json fixes the name resolution. However each new **_** must be hardcoded. This file does not exist for element.

t3chguy commented 2 years ago

[__mocks__/languages.json](https://github.com/matrix-org/matrix-react-sdk/blob/develop/__mocks__/languages.json?rgh-link-date=2022-02-06T16%3A43%3A52Z) is just that, a mock, its used for the Jest test suites and only there.

acxz commented 2 years ago

I see, my bad.

Should I go ahead and make a new issue about the output to stderr? Or should this one be reopened?

novocaine commented 2 years ago

@acxz can you post the output you are seeing that still seems broken, and the details of the version of Element that you are seeing it on? We can re-open the issue if the same log line remains visible.

acxz commented 2 years ago

Sure here is the complete log:

/home/acxz/.config/Element exists: yes
/home/acxz/.config/Riot exists: no
No update_base_url is defined: auto update is disabled
Fetching translation json for locale: en_EN
Changing application language to en-us
Fetching translation json for locale: en-us
Could not fetch translation json for locale: 'en-us' Error: Cannot find module './i18n/strings/en-us.json'
Require stack:
- /usr/lib/element/app.asar/lib/language-helper.js
- /usr/lib/element/app.asar/lib/tray.js
- /usr/lib/element/app.asar/lib/electron-main.js
- /usr/lib/electron15/resources/default_app.asar/main.js
-
    at Module._resolveFilename (node:internal/modules/cjs/loader:934:15)
    at Function.n._resolveFilename (node:electron/js2c/browser_init:249:1128)
    at Module._load (node:internal/modules/cjs/loader:779:27)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
    at Module.require (node:internal/modules/cjs/loader:1006:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at AppLocalization.fetchTranslationJson (/usr/lib/element/app.asar/lib/language-helper.js:76:20)
    at /usr/lib/element/app.asar/lib/language-helper.js:89:39
    at Array.forEach (<anonymous>)
    at AppLocalization.setAppLocale (/usr/lib/element/app.asar/lib/language-helper.js:88:17) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/lib/element/app.asar/lib/language-helper.js',
    '/usr/lib/element/app.asar/lib/tray.js',
    '/usr/lib/element/app.asar/lib/electron-main.js',
    '/usr/lib/electron15/resources/default_app.asar/main.js',
    undefined
  ]
}
Resetting the UI components after locale change
Resetting the UI components after locale change
Changing application language to en-us
Fetching translation json for locale: en-us
Could not fetch translation json for locale: 'en-us' Error: Cannot find module './i18n/strings/en-us.json'
Require stack:
- /usr/lib/element/app.asar/lib/language-helper.js
- /usr/lib/element/app.asar/lib/tray.js
- /usr/lib/element/app.asar/lib/electron-main.js
- /usr/lib/electron15/resources/default_app.asar/main.js
-
    at Module._resolveFilename (node:internal/modules/cjs/loader:934:15)
    at Function.n._resolveFilename (node:electron/js2c/browser_init:249:1128)
    at Module._load (node:internal/modules/cjs/loader:779:27)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
    at Module.require (node:internal/modules/cjs/loader:1006:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at AppLocalization.fetchTranslationJson (/usr/lib/element/app.asar/lib/language-helper.js:76:20)
    at /usr/lib/element/app.asar/lib/language-helper.js:89:39
    at Array.forEach (<anonymous>)
    at AppLocalization.setAppLocale (/usr/lib/element/app.asar/lib/language-helper.js:88:17) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/lib/element/app.asar/lib/language-helper.js',
    '/usr/lib/element/app.asar/lib/tray.js',
    '/usr/lib/element/app.asar/lib/electron-main.js',
    '/usr/lib/electron15/resources/default_app.asar/main.js',
    undefined
  ]
}
Resetting the UI components after locale change

OS: Archlinux Element version: 1.10.1

sigaloid commented 2 years ago

I'm having the same issue on Schildi Chat and Element Desktop, using the flatpak... except I can't even launch the app in either case. Fedora Linux 35 (Workstation Edition) Gnome 41.3 Wayland

novocaine commented 2 years ago

I'm having the same issue on Schildi Chat and Element Desktop, using the flatpak... except I can't even launch the app in either case. Fedora Linux 35 (Workstation Edition) Gnome 41.3 Wayland

Sorry to hear that.

As noted in the description of this issue:

This isn't a fatal issue but it does appear loudly in the stderr of every en_US Element user on Linux (or any platform where the users tend to see stderr) so it is a red herring in almost every bug report on linux.

Can you please file a separate issue?

sigaloid commented 2 years ago

Ah, I see. Oddly enough I got element to launch once and that error was gone from the logs, but I guess it was unrelated. I'll try to file a bug report in the relevant flatpak repository as I am not sure if it belongs here (correct me if I'm wrong).

TPiUnikie commented 2 years ago

Hi, patch the language language-helper.ts in Docker buildfile:

COPY language-helper.patch .
RUN patch src/language-helper.ts language-helper.patch

or directly from command line patch src/language-helper.ts language-helper.patch language-helper.zip

acxz commented 2 years ago

@TPiUnikie do you want to send in the patch as a PR? It would help all of us.

For the lazy folks to dl and unzip the zip file.

language-helper.txt

--- language-helper.ts  2022-04-12 16:16:01.175718315 +0300
+++ language-helper_tpi.ts  2022-04-12 16:14:41.283150806 +0300
@@ -92,10 +92,26 @@
         this.resetLocalizedUI();
     }

+    private denormalize(locale: string): string {
+        if (locale === "en") {
+            locale = "en-EN"
+        }
+        if (locale.indexOf("-") >= 0) {
+            const langDesc:number = 1;
+            const partsReq:number = 2;
+            var part = locale.split("-"); 
+            if (part.length >= partsReq) {
+                part[langDesc] = part[langDesc].toUpperCase()
+            }
+            return part.join("_");
+        }
+        return locale;
+    }
+    
     public fetchTranslationJson(locale: string): Record<string, string> {
         try {
             console.log("Fetching translation json for locale: " + locale);
-            return require(`./i18n/strings/${locale}.json`);
+            return require(`./i18n/strings/${this.denormalize(locale)}.json`);
         } catch (e) {
             console.log(`Could not fetch translation json for locale: '${locale}'`, e);
             return null;
acxz commented 1 year ago

Should this be closed due to the merge of https://github.com/vector-im/element-desktop/pull/339 ?