-
Notifications
You must be signed in to change notification settings - Fork 266
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
Fix Could not fetch translation json for locale: 'de' #1493
Conversation
I am not really happy with the amount of logging, as every locale that cannot be found produces a stack trace like this: 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:96:20)
at /opt/Element/resources/app.asar/lib/language-helper.js:109:39
at Array.filter (<anonymous>)
at AppLocalization.setAppLocale (/opt/Element/resources/app.asar/lib/language-helper.js:108:86) {
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
]
}
Fetching translation json for locale: de_DE
Resetting the UI components after locale change
This only affects |
e969eb7
to
0d510d0
Compare
AppLocalization.setAppLocale uses `!!translations` to check if a locale is avaliable, but `!!{} === true`. Thus, any localization was considered valid, even `{}`, which was returned from `AppLocalization.fetchTranslationJson` when no such locale was found. This does not happen when we return `null` since it is falsy. Signed-off-by: Nils Hanff <[email protected]>
The method returns suitable fallbacks in case a locale is not found. Signed-off-by: Nils Hanff <[email protected]>
Signed-off-by: Nils Hanff <[email protected]>
0d510d0
to
2ca86f7
Compare
const parts = locale.split("-"); | ||
if (parts.length > 1) { | ||
parts[1] = parts[1].toUpperCase(); | ||
} | ||
return parts.join("_"); | ||
} | ||
|
||
public fetchTranslationJson(locale: string): Record<string, string> { | ||
public fetchTranslationJson(locale: string): object | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
object
is too loose here, please use a better type
@@ -91,25 +91,35 @@ export class AppLocalization { | |||
this.resetLocalizedUI(); | |||
} | |||
|
|||
// Fallbacks to a locale (e.g. en-gb to [en-gb, en, en-en] or just en to [en, en-en]) | |||
private variations(locale: string): string[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use getNormalizedLanguageKeys
from matrix-web-i18n
to remain consistent across the layers?
Drafting this because it is not critical and seems rather complex. I'll come back once I have some more time at hand. |
Nils Hanff seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Fixes #1419.
Checklist
In implementation it turned out that it was the opposite problem than in the comment: There is no generic
de
, only the specificde_DE
. I tried to cover this case as generically as possible, although it only occurs withen
andde
at the time of writing.Type: defect