解决多语言中默认语言无法生效的问题

This commit is contained in:
锦恢 2024-11-18 16:26:05 +08:00
parent 577fd02b31
commit f1b79b92d3
20 changed files with 87 additions and 48 deletions

View File

@ -635,4 +635,29 @@ img {
.icon-parameter:before {
font-weight: 1000;
}
#write .source-lib-tag {
font-size: 0.85rem;
padding: 3px 4px;
border-radius: .5em;
background-color: rgb(35,102,93);
}
#write .source-prj-tag {
font-size: 0.85rem;
padding: 3px 4px;
border-radius: .5em;
background-color: rgb(53,59,140);
}
#write .source-unk-tag {
font-size: 0.85rem;
padding: 3px 4px;
border-radius: .5em;
background-color: #a09c9c;
}
#write table, th, td {
border: 1px solid var(--vscode-foreground) !important;
}

View File

@ -1,8 +1,8 @@
@font-face {
font-family: "iconfont"; /* Project id 4748764 */
src: url('iconfont.woff2?t=1731847061847') format('woff2'),
url('iconfont.woff?t=1731847061847') format('woff'),
url('iconfont.ttf?t=1731847061847') format('truetype');
src: url('iconfont.woff2?t=1731914985969') format('woff2'),
url('iconfont.woff?t=1731914985969') format('woff'),
url('iconfont.ttf?t=1731914985969') format('truetype');
}
.iconfont {
@ -13,6 +13,10 @@
-moz-osx-font-smoothing: grayscale;
}
.icon-tree:before {
content: "\e601";
}
.icon-verilog:before {
content: "\e634";
}

Binary file not shown.

View File

@ -9,6 +9,8 @@ import { hdlMonitor } from './monitor';
import * as lspClient from './function/lsp-client';
import { refreshArchTree } from './function/treeView';
import { hdlFile } from './hdlFs';
import { initialiseI18n, t } from './i18n';
async function registerCommand(context: vscode.ExtensionContext, packageJson: any) {
@ -34,7 +36,8 @@ function readPackageJson(context: vscode.ExtensionContext): any | undefined {
}
async function launch(context: vscode.ExtensionContext) {
const { t } = vscode.l10n;
initialiseI18n(context);
console.log(t('info.welcome.title'));
console.log(t('info.welcome.join-qq-group') + ' https://qm.qq.com/q/1M655h3GsA');
const packageJson = readPackageJson(context);

View File

@ -5,6 +5,7 @@ import { BSON } from 'bson';
import * as path from 'path';
import * as os from 'os';
import { getIconConfig } from '../../hdlFs/icons';
import { t } from '../../i18n';
export interface SaveViewData {
originVcdFile: string,
@ -80,9 +81,6 @@ function getFilename(file: string) {
export async function saveViewAs(data: any, uri: vscode.Uri, panel: vscode.WebviewPanel) {
const { t } = vscode.l10n;
try {
// 先保存原来的文件 payload 一定是 all
let { originVcdFile, originVcdViewFile, payload } = data;
@ -101,7 +99,6 @@ export async function saveViewAs(data: any, uri: vscode.Uri, panel: vscode.Webvi
const vcdFilters: Record<string, string[]> = {};
vcdFilters[t('info.vcd-viewer.vcd-view-file')] = ['view'];
vcdFilters[t('info.vcd-viewer.all-file')] = ['*'];
const saveUri = await vscode.window.showSaveDialog({
title: t('info.vcd-viewer.save-as-view'),
defaultUri: vscode.Uri.file(path.join(rootPath, defaultFilename)),
@ -137,7 +134,6 @@ export async function saveViewAs(data: any, uri: vscode.Uri, panel: vscode.Webvi
export async function loadView(data: any, uri: vscode.Uri, panel: vscode.WebviewPanel) {
const { t } = vscode.l10n;
try {
let { originVcdFile } = data;

View File

@ -7,6 +7,7 @@ import { opeParam, ReportType, WaveViewOutput } from '../../global';
import { LaunchFiles, loadView, saveView, saveViewAs } from './api';
import { BSON } from 'bson';
import { getIconConfig } from '../../hdlFs/icons';
import { t } from '../../i18n';
function getWebviewContent(context: vscode.ExtensionContext, panel?: vscode.WebviewPanel): string | undefined {
const dideviewerPath = hdlPath.join(context.extensionPath, 'resources', 'dide-viewer', 'view');
@ -202,7 +203,6 @@ function registerMessageEvent(panel: vscode.WebviewPanel, uri: vscode.Uri) {
* @returns
*/
function getViewLaunchFiles(context: vscode.ExtensionContext, uri: vscode.Uri, panel: vscode.WebviewPanel): LaunchFiles | Error {
const { t } = vscode.l10n;
const entryPath = uri.fsPath;
const dideviewerPath = hdlPath.join(context.extensionPath, 'resources', 'dide-viewer', 'view');
const workerAbsPath = hdlPath.join(dideviewerPath, 'worker.js');

View File

@ -14,6 +14,7 @@ import { getSymbolComments } from '../lsp/util/feature';
import { HdlLangID, ThemeType } from '../../global/enum';
import { makeDiagram } from './diagram';
import { defaultMacro, doFastApi } from '../../hdlParser/util';
import { t } from '../../i18n';
function makeSVGElementByLink(link: AbsPath, caption?: string) {
@ -45,12 +46,12 @@ function selectFieldValue(obj: any, subName: string, ws: string, name: string, i
if (hdlFile && hdlFile.type === 'remote_lib') {
// 如果是 库 文件,做出更加自定义的字面量
const libRelPath = value.replace(`${opeParam.extensionPath}/library/`, '');
value = `(library) [${libRelPath}](file://${value})`;
value = `<span class="source-lib-tag">library</span> [${libRelPath}](file://${value})`;
} else {
value = `(project) [${relativePath}](file://${value})`;
value = `<span class="source-prj-tag">project</span> [${relativePath}](file://${value})`;
}
} else {
value = '(unknown) ' + vscode.l10n.t('info.dide-doc.source.cannot-find');
value = '<span class="source-unk-tag">unknown</span> ' + t('info.dide-doc.source.cannot-find');
}
}
@ -123,8 +124,6 @@ async function patchComment(path: AbsPath, ports: (HdlModulePort | HdlModulePara
* @param module
*/
async function getDocsFromModule(module: HdlModule): Promise<MarkdownString> {
const { t } = vscode.l10n;
const moduleName = module.name;
const portNum = module.ports.length;
const paramNum = module.params.length;
@ -182,7 +181,8 @@ async function getDocsFromModule(module: HdlModule): Promise<MarkdownString> {
}
// param section
md.addTitle(t('info.dide-doc.parameters'), 2);
const paramTitleIcon = '<span class="iconfont icon-parameter"></span> ';
md.addTitle(paramTitleIcon + t('info.dide-doc.parameters'), 2);
if (module.params.length > 0) {
makeTableFromObjArray(md, module.params, 'params',
['name', 'init', 'empty', 'desc'],
@ -203,7 +203,8 @@ async function getDocsFromModule(module: HdlModule): Promise<MarkdownString> {
// port section
md.addTitle(t('info.dide-doc.ports'), 2);
const portTitleIcon = '<span class="iconfont icon-port"></span> ';
md.addTitle(portTitleIcon + t('info.dide-doc.ports'), 2);
if (module.ports.length > 0) {
makeTableFromObjArray(md, module.ports, 'ports',
['name', 'type', 'width', 'desc'],
@ -223,7 +224,8 @@ async function getDocsFromModule(module: HdlModule): Promise<MarkdownString> {
md.addEnter();
// dependency section
md.addTitle(t('info.dide-doc.dependency'), 2);
const depTitleIcon = '<span class="iconfont icon-tree"></span> ';
md.addTitle(depTitleIcon + t('info.dide-doc.dependency'), 2);
let insts = module.getAllInstances();
// 对于单文件模式而言,未进行 instance 搜索所以insts必然是空的
@ -269,8 +271,6 @@ async function getDocsFromModule(module: HdlModule): Promise<MarkdownString> {
* @param path absolute path of the file
*/
async function getDocsFromFile(path: AbsPath): Promise<MarkdownString[] | undefined> {
const { t } = vscode.l10n;
let moduleFile = hdlParam.getHdlFile(path);
// 没有说明是单文件模式,直接打开解析
if (!moduleFile) {

View File

@ -22,6 +22,7 @@ import { hdlPath } from '../hdlFs';
import { LspClient, opeParam } from '../global';
import { DoFastToolChainType, SyncFastRequestType } from '../global/lsp';
import { makeDocBody } from './hdlDoc/html';
import { State } from 'vscode-languageclient';
function registerDocumentation(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('digital-ide.hdlDoc.showWebview', async (uri: vscode.Uri) => {
@ -35,7 +36,7 @@ function registerDocumentation(context: vscode.ExtensionContext) {
// TODO: 注册文件变动监听
const fileChangeDisposer = vscode.window.onDidChangeActiveTextEditor(async event => {
// const client = LspClient.DigitalIDE;
// if (client && event?.document) {
// if (client && event?.document && client.state === State.Running && event.document.uri.path === uri.path) {
// const path = hdlPath.toSlash(event.document.fileName);
// const fileType = 'common';
// const toolChain = opeParam.prjInfo.toolChain as DoFastToolChainType;

View File

@ -16,6 +16,7 @@ import axios, { AxiosResponse } from "axios";
import { chooseBestDownloadSource, getGiteeDownloadLink, getGithubDownloadLink, getPlatformPlatformSignature } from "./cdn";
import { hdlDir, hdlPath } from "../../hdlFs";
import { registerConfigurationUpdater } from "./config";
import { t } from "../../i18n";
function getLspServerExecutionName() {
const osname = platform();
@ -98,8 +99,6 @@ async function checkAndDownload(context: vscode.ExtensionContext, version: strin
}
export async function downloadLsp(context: vscode.ExtensionContext, version: string, versionFolderPath: string): Promise<boolean> {
const { t } = vscode.l10n;
const downloadLink = await vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: t('info.progress.choose-best-download-source')

View File

@ -7,6 +7,7 @@ import { hdlParam } from '../../hdlParser';
import { hdlFile, hdlPath } from '../../hdlFs';
import { defaultMacro, doFastApi } from '../../hdlParser/util';
import { HdlFile } from '../../hdlParser/core';
import { t } from '../../i18n';
class Netlist {
@ -19,7 +20,6 @@ class Netlist {
}
public async open(uri: vscode.Uri) {
const { t } = vscode.l10n;
// get dependence of the current uri
const prjFiles = [];

View File

@ -4,6 +4,7 @@ import { hdlParam } from '../../hdlParser';
import { HdlModulePort, HdlModuleParam, HdlModulePortType } from '../../hdlParser/common';
import { HdlModule } from '../../hdlParser/core';
import { hdlFile, hdlPath } from '../../hdlFs';
import { t } from '../../i18n';
class ModuleInfoItem {
label: string;
@ -275,7 +276,6 @@ function getSelectItem(modules: HdlModule[]) {
* @description vscode的窗体Module中选择模块
*/
async function selectModuleFromAll() {
const { t } = vscode.l10n;
const option = {
placeHolder: t('info.command.instantiation.pick-title')
};

View File

@ -7,6 +7,7 @@ import { opeParam } from '../global';
import { hdlFile, hdlPath } from '../hdlFs';
import { ModuleDataItem } from './treeView/tree';
import { hdlParam } from '../hdlParser';
import { t } from '../i18n';
async function insertTextToUri(uri: vscode.Uri, text: string, position?: vscode.Position) {
if (!position) {
@ -47,7 +48,6 @@ const PPY_LIB_REPLACE: Record<string, string> = {
};
async function transformOldPpy() {
const { t } = vscode.l10n;
const propertyJsonPath = opeParam.propertyJsonPath;
if (fs.existsSync(propertyJsonPath)) {
const oldPpyContent = hdlFile.readJSON(propertyJsonPath) as Record<any, any>;
@ -117,7 +117,6 @@ async function transformOldPpy() {
}
async function askUserToSaveFilelist(filelist: string[]) {
const { t } = vscode.l10n;
const topModulePath = filelist[0];
const defaultSaveName = fspath.basename(topModulePath, fspath.extname(topModulePath));

View File

@ -7,6 +7,7 @@ import { hardwareTreeProvider, softwareTreeProvider, toolTreeProvider } from './
import { moduleTreeProvider, ModuleDataItem } from './tree';
import { Range } from '../../hdlParser/common';
import { MainOutput, opeParam, ReportType } from '../../global';
import { t } from '../../i18n';
async function openFileAtPosition(uri: vscode.Uri, range?: Range) {
@ -16,7 +17,7 @@ async function openFileAtPosition(uri: vscode.Uri, range?: Range) {
end: { line: 0, character: 0 }
}
}
const document = await vscode.workspace.openTextDocument(uri);
const document = await vscode.workspace.openTextDocument(uri);
const start = new vscode.Position(range.start.line, range.start.character);
const end = new vscode.Position(range.end.line, range.end.character);
@ -29,7 +30,6 @@ async function openFileAtPosition(uri: vscode.Uri, range?: Range) {
}
function openFileByUri(path: string, range: Range, element: ModuleDataItem) {
const { t } = vscode.l10n;
if (range === undefined) {
// vscode.window.showErrorMessage(`${path} not support jump yet`);
return;
@ -53,7 +53,6 @@ function openFileByUri(path: string, range: Range, element: ModuleDataItem) {
}
function gotoXilinxIPDefinition(element: ModuleDataItem) {
const { t } = vscode.l10n;
const folderPath = element.path;
if (folderPath) {
const ipName = fspath.basename(folderPath);

View File

@ -8,6 +8,7 @@ import { hdlFile, hdlPath } from '../../hdlFs';
import { xilinx, itemModes, otherModes } from './common';
import { getIconConfig } from '../../hdlFs/icons';
import { DoFastFileType } from '../../global/lsp';
import { t } from '../../i18n';
let needExpand = true;
@ -109,12 +110,10 @@ class ModuleTreeProvider implements vscode.TreeDataProvider<ModuleDataItem> {
public getTreeItem(element: ModuleDataItem): vscode.TreeItem | Thenable<vscode.TreeItem> {
const { t } = vscode.l10n;
let itemName = element.name;
if (itemModes.has(element.icon)) {
itemName = `${element.type}(${itemName})`;
}
const expandable = canExpandable(element);
let collapsibleState;
if (!expandable) {

View File

@ -11,6 +11,7 @@ import assert = require('assert');
import * as hdlPath from '../hdlFs/path';
import { hdlDir } from '../hdlFs';
import { MainOutput } from './outputChannel';
import { t } from '../i18n';
type AbsPath = string;
@ -400,7 +401,6 @@ class PrjInfo implements PrjInfoMeta {
}
public updateArch(arch?: Arch) {
const { t } = vscode.l10n;
const workspacePath = this._workspacePath;
if (arch) {
// 如果配置中存在,直接根据用户配置的项来赋值

View File

@ -9,6 +9,7 @@ import * as common from './common';
import { hdlFile, hdlPath } from '../hdlFs';
import { defaultMacro, defaultRange, doPrimitivesJudgeApi, HdlSymbol } from './util';
import { DoFastFileType } from '../global/lsp';
import { t } from '../i18n';
class HdlParam {
@ -253,10 +254,8 @@ class HdlParam {
public async initializeHdlFiles(hdlFiles: AbsPath[], progress: vscode.Progress<IProgress>) {
const { t } = vscode.l10n;
let count: number = 0;
let fileNum = hdlFiles.length;
const parallelChunk = Math.min(os.cpus().length, 32);
console.log("use cpu: " + parallelChunk);
@ -290,7 +289,6 @@ class HdlParam {
}
public async initializeIPsPath(IPsPath: string[], progress: vscode.Progress<IProgress>) {
const { t } = vscode.l10n;
let count: number = 0;
let fileNum = IPsPath.length;

24
src/i18n/index.ts Normal file
View File

@ -0,0 +1,24 @@
import * as vscode from 'vscode';
import { hdlFile } from '../hdlFs';
const defaultBundle: Record<string, string> = {}
export function initialiseI18n(context: vscode.ExtensionContext) {
if (vscode.l10n.bundle === undefined) {
const bundlePath = context.asAbsolutePath('l10n/bundle.l10n.en.json');
const bundle = hdlFile.readJSON(bundlePath) as Record<string, string>;
Object.assign(defaultBundle, bundle);
}
}
export function t(message: string, ...args: string[]): string {
if (vscode.l10n.bundle === undefined) {
let translateMessage = defaultBundle[message] || message;
for (let i = 0; i < args.length; ++ i) {
translateMessage.replace(`{${i}}`, args[i]);
}
return translateMessage;
} else {
return vscode.l10n.t(message, ...args);
}
}

View File

@ -13,6 +13,7 @@ import { moduleTreeProvider, ModuleDataItem } from '../../function/treeView/tree
import { HdlFileType } from '../../hdlParser/common';
import { PropertySchema } from '../../global/propertySchema';
import { HardwareOutput, ReportType } from '../../global/outputChannel';
import { t } from '../../i18n';
class PlManage extends BaseManage {
context: PLContext;
@ -96,7 +97,6 @@ class PlManage extends BaseManage {
}
public exit() {
const { t } = vscode.l10n;
if (this.context.process === undefined) {
return;

View File

@ -12,6 +12,7 @@ import { PropertySchema } from '../../global/propertySchema';
import { XilinxIP } from '../../global/enum';
import { HardwareOutput, MainOutput, ReportType } from '../../global/outputChannel';
import { debounce } from '../../global/util';
import { t } from '../../i18n';
interface XilinxCustom {
ipRepo: AbsPath,
@ -139,8 +140,6 @@ class XilinxOperation {
* @param context
*/
public async launch(context: PLContext): Promise<string | undefined> {
const { t } = vscode.l10n;
this.guiLaunched = false;
let scripts: string[] = [];
@ -244,7 +243,7 @@ class XilinxOperation {
}
messageBuffer.push(line);
}
const launchInfo = vscode.l10n.t('info.pl.launch.launch-info');
const launchInfo = t('info.pl.launch.launch-info');
messageBuffer.unshift(launchInfo);
return messageBuffer.join("\n");
}
@ -582,8 +581,6 @@ file delete ${scriptPath} -force\n`;
}
public async gui(context: PLContext) {
const { t } = vscode.l10n;
if (context.process === undefined) {
await this.launch(context);
}
@ -597,8 +594,6 @@ file delete ${scriptPath} -force\n`;
}
public addFiles(files: string[], context: PLContext) {
const { t } = vscode.l10n;
if (!this.guiLaunched && files.length > 0) {
const filesString = files.join("\n");
HardwareOutput.report(t('info.pl.add-files.title') + '\n' + filesString);
@ -607,8 +602,6 @@ file delete ${scriptPath} -force\n`;
}
public delFiles(files: string[], context: PLContext) {
const { t } = vscode.l10n;
if (!this.guiLaunched && files.length > 0) {
const filesString = files.join("\n");
HardwareOutput.report(t('info.pl.del-files.title') + '\n' + filesString);

View File

@ -14,6 +14,7 @@ import { libManage } from '../manager/lib';
import type { HdlMonitor } from './index';
import { HdlLangID, ToolChainType } from '../global/enum';
import { vlogLinterManager, vhdlLinterManager, svlogLinterManager } from '../function/lsp/linter';
import { t } from '../i18n';
enum Event {
Add = 'add', // emit when add file
@ -281,8 +282,6 @@ class PpyAction extends BaseAction {
public async refreshHdlMonitor(m: HdlMonitor, originalHdlFiles: AbsPath[]) {
m.remakeHdlMonitor();
const { t } = vscode.l10n;
const newFiles = await prjManage.getPrjHardwareFiles();
const { addFiles, delFiles } = this.diffNewOld(newFiles, originalHdlFiles);