Skip to content

Commit

Permalink
[IMPROVE] i18next (#1096)
Browse files Browse the repository at this point in the history
* Replace env module with process.env.NODE_ENV

* Refactor i18n module

* Remove pluralization

* Fix i18n imports

* Normalize locale strings

* Fix wrong dialog title

* Remove unused strings

* Change i18n string interpolation

* Update i18n keys

* Move empty menu to menus module

* Add i18next

* Allow asynchronous initialization of i18n

* Refactor i18n initialization

* Deactivate i18n initialization in test mode
  • Loading branch information
tassoevan authored Feb 22, 2019
1 parent 37382ca commit eae94bd
Show file tree
Hide file tree
Showing 38 changed files with 1,302 additions and 939 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ indent_style = tab

[*.i18n.json]
indent_style = space
indent_size = 2
indent_size = 4

[*.md]
trim_trailing_whitespace = false
1 change: 0 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require('./tasks/build-app');
require('./tasks/build-tests');
require('./tasks/release');
require('./tasks/start');
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"electron-updater": "^4.0.6",
"freedesktop-notifications": "^1.4.0",
"fs-jetpack": "^2.2.0",
"i18next": "^15.0.4",
"i18next-node-fs-backend": "^2.1.1",
"i18next-sync-fs-backend": "^1.1.0",
"spellchecker": "^3.5.0",
"tmp": "^0.0.33"
},
Expand All @@ -56,7 +59,6 @@
"eslint": "^5.12.0",
"gulp": "^3.9.1",
"gulp-batch": "^1.0.5",
"gulp-file": "^0.4.0",
"gulp-less": "^4.0.1",
"gulp-plumber": "^1.2.0",
"gulp-rename": "^1.4.0",
Expand All @@ -71,6 +73,7 @@
"rollup-plugin-istanbul": "^2.0.1",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-replace": "^2.1.0",
"run-sequence": "^2.2.1",
"sinon": "^7.2.2",
"spectron": "^5.0.0",
Expand Down
3 changes: 3 additions & 0 deletions servers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Test": "http://localhost:3000"
}
30 changes: 3 additions & 27 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, ipcMain, Menu } from 'electron';
import { app, ipcMain } from 'electron';
import querystring from 'querystring';
import url from 'url';
import idle from '@paulcbetts/system-idle-time';
Expand All @@ -14,36 +14,14 @@ import './background/screenshareDialog';
import tray from './background/tray';
import './background/updateDialog';
import './background/updates';

import i18n from './i18n/index.js';
import i18n from './i18n';

export { default as remoteServers } from './background/servers';
export { certificate, dock, menus, tray };


process.env.GOOGLE_API_KEY = 'AIzaSyADqUh_c1Qhji3Cp1NE43YrcpuPkmhXD-c';

const unsetDefaultApplicationMenu = () => {
if (process.platform !== 'darwin') {
Menu.setApplicationMenu(null);
return;
}

const emptyMenuTemplate = [{
label: app.getName(),
submenu: [
{
label: i18n.__('&Quit %s', app.getName()),
accelerator: 'CommandOrControl+Q',
click() {
app.quit();
},
},
],
}];
Menu.setApplicationMenu(Menu.buildFromTemplate(emptyMenuTemplate));
};

const parseProtocolUrls = (args) =>
args.filter((arg) => /^rocketchat:\/\/./.test(arg))
.map((uri) => url.parse(uri))
Expand Down Expand Up @@ -90,10 +68,8 @@ if (gotTheLock) {
});

app.on('ready', async() => {
unsetDefaultApplicationMenu();

appData.initialize();

await i18n.initialize();
const mainWindow = await getMainWindow();
certificate.initWindow(mainWindow);

Expand Down
4 changes: 2 additions & 2 deletions src/background/aboutDialog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app, BrowserWindow, ipcMain } from 'electron';
import { getMainWindow } from './mainWindow';
import i18n from '../i18n/index.js';
import i18n from '../i18n';


let aboutWindow;
Expand All @@ -12,7 +12,7 @@ const openAboutDialog = async() => {

const mainWindow = await getMainWindow();
aboutWindow = new BrowserWindow({
title: i18n.__('About %s', app.getName()),
title: i18n.__('dialog.about.title', { appName: app.getName() }),
parent: mainWindow,
modal: process.platform !== 'darwin',
width: 400,
Expand Down
5 changes: 2 additions & 3 deletions src/background/appData.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { app, ipcMain } from 'electron';
import jetpack from 'fs-jetpack';
import path from 'path';
import env from '../env';


const definePath = () => {
const appName = app.getName();
const dirName = env.name === 'production' ? appName : `${ appName } (${ env.name })`;
const dirName = process.env.NODE_ENV === 'production' ? appName : `${ appName } (${ process.env.NODE_ENV })`;

app.setPath('userData', path.join(app.getPath('appData'), dirName));
};
Expand All @@ -20,7 +19,7 @@ const reset = () => {

const migrate = () => {
const olderAppName = 'Rocket.Chat+';
const dirName = env.name === 'production' ? olderAppName : `${ olderAppName } (${ env.name })`;
const dirName = process.env.NODE_ENV === 'production' ? olderAppName : `${ olderAppName } (${ process.env.NODE_ENV })`;
const olderUserDataPath = path.join(app.getPath('appData'), dirName);

try {
Expand Down
12 changes: 6 additions & 6 deletions src/background/certificate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { app, dialog } from 'electron';
import jetpack from 'fs-jetpack';
import url from 'url';
import i18n from '../i18n/index.js';
import i18n from '../i18n';

class CertificateStore {
initWindow(win) {
Expand Down Expand Up @@ -31,17 +31,17 @@ class CertificateStore {

let detail = `URL: ${ url }\nError: ${ error }`;
if (this.isExisting(url)) {
detail = i18n.__('Certificate_error_different', detail);
detail = i18n.__('error.differentCertificate', { detail });
}

dialog.showMessageBox(this.window, {
title: i18n.__('Certificate_error'),
message: i18n.__('Certificate_error_message', certificate.issuerName),
title: i18n.__('dialog.certificateError.title'),
message: i18n.__('dialog.certificateError.message', { issuerName: certificate.issuerName }),
detail,
type: 'warning',
buttons: [
i18n.__('Yes'),
i18n.__('No'),
i18n.__('dialog.certificateError.yes'),
i18n.__('dialog.certificateError.no'),
],
cancelId: 1,
}, (response) => {
Expand Down
3 changes: 1 addition & 2 deletions src/background/mainWindow.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { app, BrowserWindow, ipcMain } from 'electron';
import createWindowStateKeeper from './windowState';
import { whenReady, whenReadyToShow } from './utils';
import env from '../env';


let mainWindow = null;
Expand Down Expand Up @@ -83,7 +82,7 @@ export const getMainWindow = async() => {
mainWindow.loadURL(`file://${ __dirname }/public/app.html`);
attachWindowStateHandling(mainWindow);

if (env.name === 'development') {
if (process.env.NODE_ENV === 'development') {
mainWindow.openDevTools();
}
}
Expand Down
Loading

0 comments on commit eae94bd

Please sign in to comment.