Skip to content

Commit

Permalink
add l10n (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
shalldie committed Oct 21, 2024
1 parent cd95940 commit fe4cdc5
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
arrowParens: 'avoid',
overrides: [
{
files: ['*.md', 'package(-lock)?.json', '*.ya?ml'],
files: ['*.md', '*.json', '*.ya?ml'],
options: {
singleQuote: false,
tabWidth: 2
Expand Down
12 changes: 12 additions & 0 deletions l10n/bundle.l10n.ja.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Show all background commands.": "backgroundのすべてのコマンドを表示します。",
"Background extension has been uninstalled. See you next time!": "Backgroundはアンインストールされています。また今度!",
"Restart vscode": "重启 vscode",
"Welcome to use background@{version}!": "ようこそbackground@{version}!",
"More": "詳細",
"Background has been disabled! Please restart.": "Backgroundは無効になっています!再起動してください。",
"Configuration has been changed, click to update.": "構成が変更されたので、更新をクリックします。",
"Update and restart": "更新と再起動",
"Backup files failed to save.": "Backup files failed to save.",
"Background has been changed! Please restart.": "Backgroundは変わった!再起動してください。"
}
12 changes: 12 additions & 0 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Show all background commands.": "Show all background commands.",
"Background extension has been uninstalled. See you next time!": "Background extension has been uninstalled. See you next time!",
"Restart vscode": "Restart vscode",
"Welcome to use background@{version}!": "Welcome to use background@{version}!",
"More": "More",
"Background has been disabled! Please restart.": "Background has been disabled! Please restart.",
"Configuration has been changed, click to update.": "Configuration has been changed, click to update.",
"Update and restart": "Update and restart",
"Backup files failed to save.": "Backup files failed to save.",
"Background has been changed! Please restart.": "Background has been changed! Please restart."
}
12 changes: 12 additions & 0 deletions l10n/bundle.l10n.zh-CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Show all background commands.": "查看 background 所有命令。",
"Background extension has been uninstalled. See you next time!": "Background 已经卸载,下次见!",
"Restart vscode": "重启 vscode",
"Welcome to use background@{version}!": "欢迎使用 background@{version}!",
"More": "更多",
"Background has been disabled! Please restart.": "Background 已经禁用! 请重启。",
"Configuration has been changed, click to update.": "配置已改变,点击更新。",
"Update and restart": "更新并重启",
"Backup files failed to save.": "Backup files failed to save.",
"Background has been changed! Please restart.": "Background 已经改变!请重启。"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"workspace"
],
"main": "./out/extension",
"l10n": "./l10n",
"contributes": {
"commands": [
{
Expand Down
34 changes: 26 additions & 8 deletions src/background/Background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import { tmpdir } from 'os';
import path from 'path';

import vscode, { Disposable, Uri } from 'vscode';
import vscode, { Disposable, l10n, Uri } from 'vscode';

import { utils } from '../utils';
import { ENCODING, EXTENSION_NAME, TOUCH_JSFILE_PATH, VERSION } from '../utils/constants';
Expand Down Expand Up @@ -71,7 +71,22 @@ export class Background implements Disposable {

if (firstLoad) {
// 提示
this.showWelcome();

vscode.window
.showInformationMessage(l10n.t('Welcome to use background@{version}!', { version: VERSION }), {
title: l10n.t('More')
})
.then(confirm => {
if (!confirm) {
return;
}
this.showWelcome();
});

// 新版本强制提示下吧
if (VERSION === '2.0.0') {
this.showWelcome();
}
// 标识插件已启动过
await fs.promises.writeFile(TOUCH_JSFILE_PATH, vscodePath.jsPath, ENCODING);
return true;
Expand Down Expand Up @@ -138,15 +153,18 @@ export class Background implements Disposable {
if (!enabled) {
if (hasInstalled) {
await this.uninstall();
vsHelp.showInfoRestart('Background has been disabled! Please restart.');
vsHelp.showInfoRestart(l10n.t('Background has been disabled! Please restart.'));
}
return;
}

// 更新,需要二次确认
const confirm = await vscode.window.showInformationMessage('Configuration has been changed, click to update.', {
title: 'Update and restart'
});
const confirm = await vscode.window.showInformationMessage(
l10n.t('Configuration has been changed, click to update.'),
{
title: l10n.t('Update and restart')
}
);

if (!confirm) {
return;
Expand Down Expand Up @@ -181,7 +199,7 @@ export class Background implements Disposable {
await this.jsFile.setup(); // backup

if (!this.jsFile.hasBackup) {
vscode.window.showErrorMessage('Backup files failed to save.');
vscode.window.showErrorMessage(l10n.t('Backup files failed to save.'));
return false;
}

Expand All @@ -194,7 +212,7 @@ export class Background implements Disposable {
// 此时一般为 vscode更新、background更新
if ([EFilePatchType.Legacy, EFilePatchType.None].includes(patchType)) {
await this.applyPatch();
vsHelp.showInfoRestart('Background has been changed! Please restart.');
vsHelp.showInfoRestart(l10n.t('Background has been changed! Please restart.'));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import vscode from 'vscode';
import vscode, { l10n } from 'vscode';

import { Background } from './background';
import { EXTENSION_ID } from './utils/constants';
Expand All @@ -15,7 +15,7 @@ function getStatusbar() {
item.command = 'extension.background.showAllCommands';
item.name = 'Background';
item.text = '$(file-media) Background';
item.tooltip = new vscode.MarkdownString(['#### Background', 'Show all background commands.'].join('\n'));
item.tooltip = new vscode.MarkdownString(['#### Background', l10n.t('Show all background commands.')].join('\n'));
item.show();

return item;
Expand Down Expand Up @@ -62,7 +62,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
// 当且仅当成功删除样式时才会卸载扩展
// 否则可能导致没有成功删掉样式时扩展就被卸载掉
await vscode.commands.executeCommand('workbench.extensions.uninstallExtension', EXTENSION_ID);
await vsHelp.showInfoRestart('Background extension has been uninstalled. See you next time!');
await vsHelp.showInfoRestart(l10n.t('Background extension has been uninstalled. See you next time!'));
}
})
);
Expand Down
6 changes: 6 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import sudo from '@vscode/sudo-prompt';
import lockfile from 'lockfile';

import { LOCK_PATH } from './constants';
import { vscode } from './vsc';

export namespace utils {
/**
* if zh-CN
*/
export const isZHCN = /^zh/.test(vscode?.env.language || '');

/**
* 等待若干时间
*
Expand Down
14 changes: 2 additions & 12 deletions src/utils/vsHelp.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import vscode from 'vscode';
import vscode, { l10n } from 'vscode';

export const vsHelp = {
/**
* 展示信息提示框
*
* @param {string} content 提示内容
* @returns {Thenable<string>}
*/
showInfo(content: string) {
return vscode.window.showInformationMessage(content);
},

/**
* 提示信息并重启
*
* @param {string} content 提示内容
* @returns {Thenable<void>}
*/
showInfoRestart(content: string): Thenable<void> {
return vscode.window.showInformationMessage(content, { title: 'Restart vscode' }).then(function (item) {
return vscode.window.showInformationMessage(content, { title: l10n.t('Restart vscode') }).then(function (item) {
if (!item) return;
vscode.commands.executeCommand('workbench.action.reloadWindow');
});
Expand Down
30 changes: 14 additions & 16 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"compilerOptions": {
"module": "Node16",
"target": "ES2022",
"outDir": "out",
"lib": [
"ES2022"
],
"sourceMap": true,
"rootDir": "src",
"esModuleInterop": true,
"strict": true /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
}
"compilerOptions": {
"module": "Node16",
"target": "ES2022",
"outDir": "out",
"lib": ["ES2022"],
"sourceMap": true,
"rootDir": "src",
"esModuleInterop": true,
"strict": true /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
}
}

0 comments on commit fe4cdc5

Please sign in to comment.