mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-16 03:41:29 +00:00
i18n: Setup module and add translation-util.js
* Add i18n package. * Use system locale for TranslationUtil.
This commit is contained in:
committed by
Akash Nimare
parent
cf96e94470
commit
77a1fc0bd3
29
app/renderer/js/utils/translation-util.js
Normal file
29
app/renderer/js/utils/translation-util.js
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
const path = require("path");
|
||||
const electron = require("electron");
|
||||
const i18n = require("i18n");
|
||||
let instance = null;
|
||||
let app = null;
|
||||
/* To make the util runnable in both main and renderer process */
|
||||
if (process.type === 'renderer') {
|
||||
app = electron.remote.app;
|
||||
}
|
||||
else {
|
||||
app = electron.app;
|
||||
}
|
||||
class TranslationUtil {
|
||||
constructor() {
|
||||
if (instance) {
|
||||
return this;
|
||||
}
|
||||
instance = this;
|
||||
i18n.configure({
|
||||
directory: path.join(__dirname, '../../../translations/'),
|
||||
register: this
|
||||
});
|
||||
}
|
||||
__(phrase) {
|
||||
return i18n.__({ phrase, locale: app.getLocale() });
|
||||
}
|
||||
}
|
||||
module.exports = new TranslationUtil();
|
||||
Reference in New Issue
Block a user