[PM-5144] Use sync fs in desktop i18n loading (#7114)

This commit is contained in:
Daniel García 2023-12-08 12:15:46 +01:00 committed by GitHub
parent c8c52957a0
commit db3bbc0aea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { promises as fs } from "fs";
import * as fs from "fs";
import * as path from "path";
import { ipcMain } from "electron";
@ -76,14 +76,14 @@ export class I18nMainService extends BaseI18nService {
];
}
private async readLanguageFile(formattedLocale: string): Promise<any> {
private readLanguageFile(formattedLocale: string): Promise<any> {
// Check that the provided locale only contains letters and dashes and underscores to avoid possible path traversal
if (!/^[a-zA-Z_-]+$/.test(formattedLocale)) {
return Promise.resolve({});
}
const filePath = path.join(__dirname, this.localesDirectory, formattedLocale, "messages.json");
const localesJson = await fs.readFile(filePath, "utf8");
const localesJson = fs.readFileSync(filePath, "utf8");
const locales = JSON.parse(localesJson.replace(/^\uFEFF/, "")); // strip the BOM
return Promise.resolve(locales);
}