Skip to content

Commit 17e87e6

Browse files
authored
IMPROVED: languages are now dynamically loaded so added a new lang is as easy as adding a new json file (#57)
UPDATED: readme with instructions for adding a new language UPDATED: typescript to latest 5.1.0
1 parent c15bd0d commit 17e87e6

File tree

8 files changed

+51
-30
lines changed

8 files changed

+51
-30
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ React-Explorer can also be built for a single patform. For example, to build onl
7575
npm run dist-win
7676
```
7777

78+
## Localization
79+
80+
React-Explorer is fully localized using `.json` files. Right now, English and French are available.
81+
82+
Adding a new language to React-Explorer is easy: simply duplicate one of the file found in [src/locale/lang](https://github.com/warpdesign/react-explorer/tree/master/src/locale/lang) directory.
83+
84+
The new file should have the name `code.json` where code is a valid language code, for example: `ja.json` to add support for Japanese.
85+
7886
## How to develop a new Plugin
7987

8088
React-Explorer has been written so that it can easily be extended using plugins.

package-lock.json

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@types/i18next": "^12.1.0",
5050
"@types/react-i18next": "^8.1.0",
5151
"@types/react-virtualized": "^9.18.12",
52+
"@types/webpack-env": "^1.13.9",
5253
"awesome-typescript-loader": "^5.2.1",
5354
"aws-sdk": "^2.332.0",
5455
"clean-webpack-plugin": "^2.0.2",
@@ -62,7 +63,7 @@
6263
"html-webpack-plugin": "^3.2.0",
6364
"source-map-loader": "^0.2.4",
6465
"style-loader": "^0.23.0",
65-
"typescript": "^3.1.1",
66+
"typescript": "^3.5.1",
6667
"url-loader": "^1.1.2",
6768
"webpack": "^4.30.0",
6869
"webpack-cli": "^3.1.2"
@@ -91,4 +92,4 @@
9192
"react-i18next": "^8.4.0",
9293
"react-virtualized": "^9.21.0"
9394
}
94-
}
95+
}

src/components/App.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AppState } from "../state/appState";
22
import * as React from "react";
33
import * as ReactDOM from "react-dom";
4-
import { FocusStyleManager, Icon, HotkeysTarget, Hotkeys, Hotkey, Alert, Popover, Classes } from "@blueprintjs/core";
4+
import { FocusStyleManager, Icon, HotkeysTarget, Hotkeys, Hotkey, Alert, Popover, Classes, IHotkeysProps } from "@blueprintjs/core";
55
import { Provider, observer, inject } from "mobx-react";
66
import { Navbar, Alignment, Button, Intent } from "@blueprintjs/core";
77
import { SideView } from "./SideView";
@@ -317,10 +317,10 @@ class App extends React.Component<WithNamespaces, IState> {
317317
</Accelerators>;
318318
}
319319

320-
public renderHotkeys() {
320+
public renderHotkeys(): React.ReactElement<IHotkeysProps> {
321321
const t = this.props.t;
322322

323-
return <Hotkeys>
323+
return (<Hotkeys>
324324
<Hotkey
325325
global={true}
326326
combo="alt + mod + l"
@@ -451,7 +451,7 @@ class App extends React.Component<WithNamespaces, IState> {
451451
onKeyDown={this.onDebugCache}
452452
group={t('SHORTCUT.GROUP.ACTIVE_VIEW')}
453453
/>
454-
</Hotkeys>;
454+
</Hotkeys>) as React.ReactElement<IHotkeysProps>;
455455
}
456456

457457
onDebugCache = () => {

src/components/FileTable.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { IconName, Icon, Classes, HotkeysTarget, Hotkeys, Hotkey } from '@blueprintjs/core';
2+
import { IconName, Icon, Classes, HotkeysTarget, Hotkeys, Hotkey, IHotkeysProps } from '@blueprintjs/core';
33
import { Column, Table, AutoSizer, Index, HeaderMouseEventHandlerParams } from 'react-virtualized';
44
import { AppState } from '../state/appState';
55
import { WithNamespaces, withNamespaces } from 'react-i18next';
@@ -168,10 +168,10 @@ export class FileTableClass extends React.Component<IProps, IState> {
168168
</Accelerators>;
169169
}
170170

171-
renderHotkeys() {
171+
renderHotkeys(): React.ReactElement<IHotkeysProps> {
172172
const { t } = this.props;
173173

174-
return <Hotkeys>
174+
return (<Hotkeys>
175175
<Hotkey
176176
global={true}
177177
combo="mod + o"
@@ -200,7 +200,7 @@ export class FileTableClass extends React.Component<IProps, IState> {
200200
onKeyDown={this.onInvertSelection}
201201
group={t('SHORTCUT.GROUP.ACTIVE_VIEW')}>
202202
</Hotkey>
203-
</Hotkeys>;
203+
</Hotkeys>) as React.ReactElement<IHotkeysProps>;
204204
}
205205

206206
private get injected() {

src/components/Log.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { observer } from 'mobx-react';
33
import { observable, runInAction } from 'mobx';
44
import { debounce } from '../utils/debounce';
5-
import { Intent, HotkeysTarget, Hotkeys, Hotkey, Classes } from '@blueprintjs/core';
5+
import { Intent, HotkeysTarget, Hotkeys, Hotkey, Classes, IHotkeysProps } from '@blueprintjs/core';
66
import { WithNamespaces, withNamespaces } from 'react-i18next';
77
import { shouldCatchEvent } from '../utils/dom';
88
import classnames from 'classnames';
@@ -123,17 +123,17 @@ export class LogUIClass extends React.Component<WithNamespaces, LogUIState> {
123123
});
124124
}
125125

126-
renderHotkeys() {
126+
renderHotkeys(): React.ReactElement<IHotkeysProps> {
127127
const { t } = this.props;
128128

129-
return <Hotkeys>
129+
return (<Hotkeys>
130130
<Hotkey
131131
global={true}
132132
combo="escape"
133133
label={t('SHORTCUT.LOG.TOGGLE')}
134134
onKeyDown={this.toggleConsole}>
135135
</Hotkey>
136-
</Hotkeys>;
136+
</Hotkeys>) as React.ReactElement<IHotkeysProps>;
137137
}
138138

139139
// shouldComponentUpdate() {

src/components/Toolbar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from "react";
22
import { reaction, IReactionDisposer } from 'mobx';
33
import { inject, observer } from 'mobx-react';
4-
import { InputGroup, ControlGroup, Button, ButtonGroup, Popover, Intent, Alert, ProgressBar, Classes, HotkeysTarget, Hotkeys, Hotkey, Tooltip, Position } from '@blueprintjs/core';
4+
import { InputGroup, ControlGroup, Button, ButtonGroup, Popover, Intent, Alert, ProgressBar, Classes, HotkeysTarget, Hotkeys, Hotkey, Tooltip, Position, IHotkeysProps } from '@blueprintjs/core';
55
import { AppState } from "../state/appState";
66
import { FileMenu } from "./FileMenu";
77
import { MakedirDialog } from "./dialogs/MakedirDialog";
@@ -303,10 +303,10 @@ export class ToolbarClass extends React.Component<IProps, PathInputState> {
303303
</Accelerators>;
304304
}
305305

306-
public renderHotkeys() {
306+
public renderHotkeys(): React.ReactElement<IHotkeysProps> {
307307
const { t } = this.props;
308308

309-
return <Hotkeys>
309+
return (<Hotkeys>
310310
<Hotkey
311311
global={true}
312312
combo="mod+l"
@@ -328,7 +328,7 @@ export class ToolbarClass extends React.Component<IProps, PathInputState> {
328328
onKeyDown={this.onDelete}
329329
group={t('SHORTCUT.GROUP.ACTIVE_VIEW')}
330330
/> */}
331-
</Hotkeys>;
331+
</Hotkeys>) as React.ReactElement<IHotkeysProps>;
332332
}
333333

334334

src/locale/i18n.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import i18next from 'i18next';
2-
import * as en from './lang/en.json';
3-
import * as fr from './lang/fr.json';
42
import { ipcRenderer } from 'electron';
53

6-
i18next
7-
.init({
4+
const locales: any = {};
5+
6+
function importAllLocales(r: any) {
7+
r.keys().forEach((key: any) => {
8+
const code = key.match(/([a-zA-Z]+)\.json$/)[1];
9+
locales[code] = r(key);
10+
});
11+
}
12+
13+
importAllLocales(require['context']('./lang/', true, /\.json$/));
14+
15+
i18next
16+
.init({
817
lng: 'en',
918
// we init with resources
10-
resources: {
11-
en: en,
12-
fr: fr
13-
},
19+
resources: locales,
1420
fallbackLng: 'en',
1521
debug: true,
1622

0 commit comments

Comments
 (0)