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

Element desktop does not have an en_US translation #871

Closed
novocaine opened this issue Sep 29, 2021 · 13 comments
Closed

Element desktop does not have an en_US translation #871

novocaine opened this issue Sep 29, 2021 · 13 comments
Labels

Comments

@novocaine
Copy link
Contributor

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
Copy link
Contributor Author

@novocaine
Copy link
Contributor Author

Fixed in #275

@acxz
Copy link

acxz commented Feb 6, 2022

@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
Copy link
Member

t3chguy commented Feb 7, 2022

[__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
Copy link

acxz commented Feb 9, 2022

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
Copy link
Contributor Author

@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
Copy link

acxz commented Feb 10, 2022

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

@novocaine novocaine reopened this Feb 10, 2022
@sigaloid
Copy link

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
Copy link
Contributor Author

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
Copy link

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
Copy link
Contributor

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
Copy link

acxz commented Apr 13, 2022

@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
Copy link

acxz commented Apr 27, 2023

Should this be closed due to the merge of #339 ?

@t3chguy t3chguy closed this as completed Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants