js: Explode singleton classes to modules.

Singleton classes may have a purpose.  This was not that purpose.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-03-03 19:56:38 -08:00
committed by Anders Kaseorg
parent d9f6cf4cc9
commit 220aac2d54
13 changed files with 688 additions and 866 deletions

View File

@@ -4,7 +4,6 @@ import path = require('path');
import electron = require('electron');
import i18n = require('i18n');
let instance: TranslationUtil = null;
let app: Electron.App = null;
/* To make the util runnable in both main and renderer process */
@@ -14,22 +13,10 @@ if (process.type === 'renderer') {
app = electron.app;
}
class TranslationUtil {
constructor() {
if (instance) {
return this;
}
i18n.configure({
directory: path.join(__dirname, '../../../translations/')
});
instance = this;
i18n.configure({
directory: path.join(__dirname, '../../../translations/'),
register: this
});
}
__(phrase: string): string {
return i18n.__({ phrase, locale: app.getLocale() ? app.getLocale() : 'en' });
}
export function __(phrase: string): string {
return i18n.__({ phrase, locale: app.getLocale() ? app.getLocale() : 'en' });
}
export = new TranslationUtil();