Skip to content

Commit f1d9012

Browse files
feat: provider supports custom locale (#473)
* feat: add locals default extensions * feat: add localeService adaptation and judgment * feat: cancel the internationalization interface in the provider * feat: add extension service adaptation for internationalization functionality * feat: specify language packages using package * feat: code to beautify * feat: add an international extension interface * feat: provider supports custom locale * feat: remove the locals package configuration file * feat: removes the settings on package from extends * fix: correct spelling mistakes * feat: remove unnecessary interfaces * feat: redefine locales interface * test: snapshot processing for locales * feat: extract internationalization constants that are started by default * test: switch matching error in internationalization execution * perf: sorting out useless methods * fix: setting service effect does not change during internationalization modification * feat: add custom extension languages * feat: provide initialization at provider * feat: add locales-plus extensions * feat: adds method called by the language package * feat: added english internationalization extension * fix: verify that the local service language is abnormal * feat: add localels setting operation * fix: adjust the timing of loading language extensions and improve built-in modules (#478) * fix: adjust the timing of loading language extensions and improve built-in modules * test: update the built-in modules in tests * test: support builtin function single test * fix: maintain single test defaults Co-authored-by: 野迂迂 <yangwei1@outlook.com>
1 parent 98ca743 commit f1d9012

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1063
-813
lines changed

src/controller/__tests__/editorTree.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('The editor tree controller', () => {
2222
const {
2323
groupToolbar,
2424
...restEditor
25-
} = modules.builtInExplorerEditorPanel;
25+
} = modules.builtInExplorerEditorPanel();
2626
expect(data[0]).toEqual(expect.objectContaining(restEditor));
2727

2828
explorerService.reset();

src/controller/__tests__/explorer.test.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,28 @@ describe('The explorer controller', () => {
2323
explorerController.initView();
2424

2525
const { headerToolBar, data } = explorerService.getState();
26-
expect(headerToolBar).not.toBeUndefined();
27-
expect(headerToolBar!.id).toBe(modules.builtInExplorerHeaderToolbar.id);
28-
expect(headerToolBar!.icon).toBe(
29-
modules.builtInExplorerHeaderToolbar.icon
30-
);
31-
expect(headerToolBar!.title).toBe(
32-
modules.builtInExplorerHeaderToolbar.title
33-
);
26+
const { id, icon, title } = modules.builtInExplorerHeaderToolbar();
27+
expect(headerToolBar!.id).toBe(id);
28+
expect(headerToolBar!.icon).toBe(icon);
29+
expect(headerToolBar!.title).toBe(title);
3430
expect(headerToolBar!.contextMenu).toHaveLength(1);
3531

3632
expect(data).toHaveLength(1);
3733
expect(data[0]).toEqual(
38-
expect.objectContaining(modules.builtInExplorerFolderPanel)
34+
expect.objectContaining(modules.builtInExplorerFolderPanel())
3935
);
4036

4137
const {
4238
data: activityBarData,
4339
selected,
4440
} = activityBarService.getState();
41+
const builtInExplorerActivityItem = modules.builtInExplorerActivityItem();
42+
4543
expect(activityBarData).toHaveLength(1);
4644
expect(activityBarData![0]).toEqual(
47-
expect.objectContaining(modules.builtInExplorerActivityItem)
45+
expect.objectContaining(builtInExplorerActivityItem)
4846
);
49-
expect(selected).toBe(modules.builtInExplorerActivityItem.id);
47+
expect(selected).toBe(builtInExplorerActivityItem.id);
5048

5149
const { current, panes } = sidebarService.getState();
5250
expect(panes).toHaveLength(1);

src/controller/__tests__/folderTree.test.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ describe('The folder tree controller', () => {
2121
folderTreeController.initView();
2222

2323
const { folderTree } = folderTreeService.getState();
24-
expect(folderTree?.contextMenu).toEqual(modules.COMMON_CONTEXT_MENU);
24+
expect(folderTree?.contextMenu).toEqual(
25+
modules.COMMON_CONTEXT_MENU?.()
26+
);
2527
expect(folderTree?.folderPanelContextMenu).toEqual(
26-
modules.FOLDER_PANEL_CONTEXT_MENU
28+
modules.FOLDER_PANEL_CONTEXT_MENU?.()
2729
);
2830
expect(folderTreeService.getFileContextMenu()).toEqual(
29-
modules.FILE_CONTEXT_MENU
31+
modules.FILE_CONTEXT_MENU?.()
3032
);
3133
expect(folderTreeService.getFolderContextMenu()).toEqual(
32-
modules.BASE_CONTEXT_MENU
34+
modules.BASE_CONTEXT_MENU?.()
3335
);
3436

3537
reset();
@@ -160,24 +162,24 @@ describe('The folder tree controller', () => {
160162
let menus = folderTreeController.onRightClick(mockTreeNode);
161163

162164
expect(menus).toEqual([
163-
...modules.FILE_CONTEXT_MENU,
164-
...modules.COMMON_CONTEXT_MENU,
165+
...modules.FILE_CONTEXT_MENU(),
166+
...modules.COMMON_CONTEXT_MENU(),
165167
]);
166168

167169
// get the folder contextMenus
168170
mockTreeNode.fileType = FileTypes.Folder;
169171
menus = folderTreeController.onRightClick(mockTreeNode);
170172
expect(menus).toEqual([
171-
...modules.BASE_CONTEXT_MENU,
172-
...modules.COMMON_CONTEXT_MENU,
173+
...modules.BASE_CONTEXT_MENU(),
174+
...modules.COMMON_CONTEXT_MENU(),
173175
]);
174176

175177
// get the root folder contextMenus
176178
mockTreeNode.fileType = FileTypes.RootFolder;
177179
menus = folderTreeController.onRightClick(mockTreeNode);
178180
expect(menus).toEqual([
179-
...modules.BASE_CONTEXT_MENU,
180-
...modules.ROOT_FOLDER_CONTEXT_MENU,
181+
...modules.BASE_CONTEXT_MENU(),
182+
...modules.ROOT_FOLDER_CONTEXT_MENU(),
181183
]);
182184

183185
// error fileTypes

src/controller/__tests__/menuBar.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('The menuBar controller', () => {
1818
menuBarController.initView();
1919

2020
expect(menuBarService.getState().data).toEqual(
21-
modules.builtInMenuBarData
21+
modules.builtInMenuBarData()
2222
);
2323
menuBarService.reset();
2424
});

src/controller/__tests__/notification.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ describe('The notification controller', () => {
2525

2626
const states = notificationService.getState();
2727
const actionBar = [
28-
modules.NOTIFICATION_CLEAR_ALL,
29-
modules.NOTIFICATION_HIDE,
28+
modules.NOTIFICATION_CLEAR_ALL?.(),
29+
modules.NOTIFICATION_HIDE?.(),
3030
];
3131
const defaults = {
3232
...modules.builtInNotification,

src/controller/__tests__/outline.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('The outline controller', () => {
1616
const { data } = explorerService.getState();
1717
expect(data).toHaveLength(1);
1818
expect(data[0]).toEqual(
19-
expect.objectContaining(modules.builtInExplorerOutlinePanel)
19+
expect.objectContaining(modules.builtInExplorerOutlinePanel())
2020
);
2121

2222
explorerService.reset();

src/controller/__tests__/panel.test.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ describe('The panel controller', () => {
1717
const { current, data, toolbox } = panelService.getState();
1818
expect(data).toHaveLength(1);
1919
expect(data![0]).toEqual(
20-
expect.objectContaining(modules.builtInOutputPanel)
20+
expect.objectContaining(modules.builtInOutputPanel())
2121
);
2222
expect(current).toEqual(
23-
expect.objectContaining(modules.builtInOutputPanel)
23+
expect.objectContaining(modules.builtInOutputPanel())
2424
);
2525

2626
expect(toolbox).toHaveLength(2);
2727
expect(toolbox).toEqual([
28-
modules.builtInPanelToolboxResize,
29-
modules.builtInPanelToolbox,
28+
modules.builtInPanelToolboxResize(),
29+
modules.builtInPanelToolbox(),
3030
]);
3131

3232
panelService.reset();
@@ -54,23 +54,23 @@ describe('The panel controller', () => {
5454
const mockFn = jest.fn();
5555
panelService.onTabChange(mockFn);
5656

57-
panelController.onTabChange(modules.builtInOutputPanel.id);
57+
panelController.onTabChange(modules.builtInOutputPanel().id);
5858

5959
expect(panelService.getState().current).toEqual(
60-
expect.objectContaining(modules.builtInOutputPanel)
60+
expect.objectContaining(modules.builtInOutputPanel())
6161
);
6262
expect(mockFn).toBeCalled();
63-
expect(mockFn.mock.calls[0][0]).toBe(modules.builtInOutputPanel.id);
63+
expect(mockFn.mock.calls[0][0]).toBe(modules.builtInOutputPanel().id);
6464
});
6565

6666
test('Should support to subscribe onClose', () => {
6767
const mockFn = jest.fn();
6868
panelService.onTabClose(mockFn);
6969

70-
panelController.onClose(modules.builtInOutputPanel.id);
70+
panelController.onClose(modules.builtInOutputPanel().id);
7171

7272
expect(mockFn).toBeCalled();
73-
expect(mockFn.mock.calls[0][0]).toBe(modules.builtInOutputPanel.id);
73+
expect(mockFn.mock.calls[0][0]).toBe(modules.builtInOutputPanel().id);
7474
});
7575

7676
test('Should support to execute onToolbarClick', () => {

src/controller/__tests__/problems.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ describe('The problems controller', () => {
3232
expect(name).toBe(constants.PROBLEM_MODEL_NAME);
3333

3434
const defaultStatus = statusBarService.getStatusBarItem(
35-
modules.builtInStatusProblems.id,
35+
modules.builtInStatusProblems().id,
3636
Float.left
3737
);
3838
expect(defaultStatus).not.toBeNull();
3939
expect(defaultStatus).toEqual(
40-
expect.objectContaining(modules.builtInStatusProblems)
40+
expect.objectContaining(modules.builtInStatusProblems())
4141
);
4242

4343
const defaultPanel = panelService.getPanel(
44-
modules.builtInPanelProblems.id
44+
modules.builtInPanelProblems().id
4545
);
4646
const { current } = panelService.getState();
4747
expect(defaultPanel).not.toBeNull();
@@ -56,13 +56,13 @@ describe('The problems controller', () => {
5656

5757
problemsController.initView();
5858
const defaultStatus = statusBarService.getStatusBarItem(
59-
modules.builtInStatusProblems.id,
59+
modules.builtInStatusProblems().id,
6060
Float.left
6161
);
6262
expect(defaultStatus).toBeNull();
6363

6464
const defaultPanel = panelService.getPanel(
65-
modules.builtInPanelProblems.id
65+
modules.builtInPanelProblems().id
6666
);
6767
const { current } = panelService.getState();
6868
expect(defaultPanel).toBeUndefined();
@@ -84,7 +84,7 @@ describe('The problems controller', () => {
8484

8585
const { current } = panelService.getState();
8686
expect(current).toEqual(
87-
expect.objectContaining(modules.builtInPanelProblems)
87+
expect.objectContaining(modules.builtInPanelProblems())
8888
);
8989
monacoService.commandService.executeCommand = original;
9090
});

src/controller/__tests__/search.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ describe('The search controller', () => {
3636
expect(searchService.getState().replaceAddons).toHaveLength(0);
3737
expect(activityBarService.getState().data).toHaveLength(1);
3838
expect(activityBarService.getState().data![0]).toEqual(
39-
expect.objectContaining(modules.builtInSearchActivityItem)
39+
expect.objectContaining(modules.builtInSearchActivityItem())
4040
);
4141

4242
expect(sidebarService.getState().panes).toHaveLength(1);
4343
expect(sidebarService.getState().panes[0]).toEqual(
4444
expect.objectContaining({
45-
id: modules.builtInSearchActivityItem.id,
45+
id: modules.builtInSearchActivityItem().id,
4646
title: 'SEARCH',
4747
})
4848
);
@@ -60,9 +60,9 @@ describe('The search controller', () => {
6060
replaceAddons,
6161
} = searchService.getState();
6262

63-
expect(headerToolBar).toEqual(modules.builtInHeaderToolbar);
64-
expect(searchAddons).toEqual(modules.builtInSearchAddons);
65-
expect(replaceAddons).toEqual(modules.builtInReplaceAddons);
63+
expect(headerToolBar).toEqual(modules.builtInHeaderToolbar());
64+
expect(searchAddons).toEqual(modules.builtInSearchAddons());
65+
expect(replaceAddons).toEqual(modules.builtInReplaceAddons());
6666
});
6767

6868
test('Should validate the value', () => {

src/controller/__tests__/statusBar.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('The statusBar controller', () => {
2323
expect(leftItems).toHaveLength(0);
2424
expect(contextMenu).toHaveLength(1);
2525
expect(rightItems[0]).toEqual(
26-
expect.objectContaining(modules.STATUS_EDITOR_INFO)
26+
expect.objectContaining(modules.STATUS_EDITOR_INFO?.())
2727
);
2828

2929
statusBarService.reset();

src/extensions/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ExtendsActivityBar } from './activityBar';
33
import { ExtendsPanel } from './panel';
44
import { ExtendsExplorer } from './explorer';
55
import { ExtendsEditorTree } from './editorTree';
6+
import { ExtendsLocales } from './locales-defaults';
67

78
import { defaultColorThemeExtension } from './theme-defaults';
89
import { monokaiColorThemeExtension } from './theme-monokai';
@@ -18,6 +19,7 @@ export const defaultExtensions = [
1819
ExtendsActivityBar,
1920
ExtendsExplorer,
2021
ExtendsEditorTree,
22+
ExtendsLocales,
2123
defaultColorThemeExtension,
2224
monokaiColorThemeExtension,
2325
paleNightColorThemeExtension,
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { IExtension, IContributeType } from 'mo/model/extension';
2+
3+
const zhCN = require('./locales/zh-CN.json');
4+
const en = require('./locales/en.json');
5+
const locales = [zhCN, en];
6+
7+
export const ExtendsLocales: IExtension = {
8+
id: 'ExtendsLocales',
9+
name: 'Extends locales',
10+
contributes: {
11+
[IContributeType.Languages]: locales,
12+
},
13+
activate() {},
14+
dispose() {},
15+
};
16+
export const BuiltInLocales = locales;
17+
export const BuiltInId = en.id;
18+
export const BuiltInDefault = locales.find((item) => item.id === BuiltInId);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"id": "en",
3+
"name": "English",
4+
"source": {
5+
"molecule.welcome": "Welcome to Molecule",
6+
"menu.file": "File",
7+
"menu.settings": "Settings",
8+
"menu.colorTheme": "Color Theme",
9+
"menu.newFile": "New File",
10+
"menu.newFolder": "New Folder",
11+
"menu.open": "Open",
12+
"menu.edit": "Edit",
13+
"menu.undo": "Undo",
14+
"menu.redo": "Redo",
15+
"menu.selection": "Selection",
16+
"menu.selectAll": "Select All",
17+
"menu.copyLineUp": "Copy Line Up",
18+
"menu.view": "View",
19+
"menu.commandPalette": "Command Palette",
20+
"menu.openView": "Open View",
21+
"menu.appearance": "Appearance",
22+
"menu.showMenuBar": "Show Menu Bar",
23+
"menu.showSideBar": "Show Side bar",
24+
"menu.showSideBar.label": "Toggle Side Bar Visibility",
25+
"menu.showStatusBar": "Show Status Bar",
26+
"menu.showActivityBar": "Show Activity Bar",
27+
"menu.showPanel": "Show Panel",
28+
"menu.showPanel.title": "Toggle Panel",
29+
"menu.run": "Run",
30+
"menu.help": "Help",
31+
"sidebar.explore.title": "Explorer",
32+
"sidebar.explore.folders": "Folders",
33+
"sidebar.explore.openEditor": "Open Editors",
34+
"sidebar.explore.openEditor.group": "Group ${i}",
35+
"sidebar.explore.outline": "Outline",
36+
"sidebar.search.title": "Search",
37+
"sidebar.replace.placement": "Replace",
38+
"sidebar.explore.refresh": "Refresh Explorer",
39+
"sidebar.explore.collapseFolders": "Collapse Folders in Explorer",
40+
"sidebar.explore.toggleVertical": "Toggle Vertical",
41+
"sidebar.explore.saveAll": "Save All",
42+
"sidebar.explore.actionDesc": "View and More Actions...",
43+
"sidebar.explore.outlineMore": "More Actions...",
44+
"toolbar.refresh": "Refresh",
45+
"toolbar.clearAll": "Clear all",
46+
"toolbar.collapseAll": "Collapse all",
47+
"search.matchCase": "Match Case",
48+
"search.matchWholeWord": "Match Whole Word",
49+
"search.useRegularExpression": "Use Regular Expression",
50+
"search.preserveCase": "Preserve Case",
51+
"search.replaceAll": "Replace All",
52+
"panel.output.title": "output",
53+
"panel.toolbox.closePanel": "Close Panel",
54+
"panel.toolbox.maximize": "Maximize Panel Size",
55+
"panel.toolbox.restoreSize": "Restore Panel Size",
56+
"panel.problems.title": "Problems",
57+
"panel.problems.empty": "No problems have been detected in the workspace.",
58+
"notification.title": "Notifications",
59+
"notification.title.no": "No new notifications",
60+
"editor.closeToRight": "Close To Right",
61+
"editor.closeToLeft": "Close To Left",
62+
"editor.closeAll": "Close All",
63+
"editor.closeSaved": "Close Saved",
64+
"editor.closeOthers": "Close Others",
65+
"editor.close": "Close",
66+
"editor.actions.splitRight": "Split Editor Right",
67+
"editor.showOpenEditors": "Show Opened Editors",
68+
"contextmenu.rename": "Rename",
69+
"contextmenu.delete": "Delete",
70+
"contextmenu.newFile": "New File",
71+
"contextmenu.newFolder": "New Folder",
72+
"contextmenu.removeFolder": "Remove Folder",
73+
"contextmenu.openToTheSide": "Open to the Side",
74+
"contextmenu.addFolderToSpace": "Add Folder to Workspace...",
75+
"contextmenu.findInSpace": "Find in Workspace...",
76+
"contextmenu.download": "Download..."
77+
}
78+
}
File renamed without changes.

src/extensions/theme-defaults/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ const defaultHC: IColorTheme = require('./themes/hc_black_defaults.json');
1414
// Theme
1515
const darkPlus: IColorTheme = require('./themes/dark_plus.json');
1616
Object.assign(darkPlus, defaultDark);
17+
1718
const darkVS: IColorTheme = require('./themes/dark_vs.json');
1819
Object.assign(darkVS, defaultDark);
1920

2021
const lightPlus: IColorTheme = require('./themes/light_plus.json');
2122
Object.assign(lightPlus, defaultLight);
23+
2224
const lightVS: IColorTheme = require('./themes/light_vs.json');
2325
Object.assign(lightVS, defaultLight);
2426

0 commit comments

Comments
 (0)