Skip to content

Commit f686a8e

Browse files
committed
翻訳が適用されない問題を修正中
1 parent d8ad303 commit f686a8e

File tree

6 files changed

+147
-121
lines changed

6 files changed

+147
-121
lines changed

l10n/bundle.l10n.ja.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"Detect U+FFFD (replacement character)": "U+FFFD(置換文字)の検出",
3+
"Current File": "現在のファイル",
4+
"Search in the current file only": "現在のファイルのみ検索",
5+
"Workspace": "ワークスペース",
6+
"Search in all files in the workspace": "ワークスペース内のすべてのファイルを検索",
7+
"Select search scope": "検索範囲を選択",
8+
"No active text editor": "アクティブなテキストエディターがありません",
9+
"extension.replacementCharacterFound": "extension.replacementCharacterFound",
10+
"No {0} found": "{0} は見つかりませんでした",
11+
"Searching for replacement characters...": "置換文字を検索しています...",
12+
"Checking {0}...": "{0} を確認しています...",
13+
"No '{0}' found in workspace": "ワークスペース内に '{0}' は見つかりませんでした"
14+
}

l10n/bundle.l10n.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{
2-
"extension.noActiveEditor": "No active text editor",
3-
"extension.replacementCharacterFound": "Found {0} U+FFFD (replacement character)",
4-
"extension.noReplacementCharactersFound": "No U+FFFD found",
5-
"extension.replacementCharacterHover": "Detect U+FFFD (replacement character)",
6-
"extension.searching": "Searching for replacement characters...",
7-
"extension.checking": "Checking {0}...",
8-
"extension.workspaceSearchResult": "Found {0} U+FFFD (replacement character) in workspace",
9-
"extension.workspaceSearchNoResult": "No U+FFFD found in workspace"
2+
"Detect U+FFFD (replacement character)": "Detect U+FFFD (replacement character)",
3+
"Current File": "Current File",
4+
"Search in the current file only": "Search in the current file only",
5+
"Workspace": "Workspace",
6+
"Search in all files in the workspace": "Search in all files in the workspace",
7+
"Select search scope": "Select search scope",
8+
"No active text editor": "No active text editor",
9+
"extension.replacementCharacterFound": "extension.replacementCharacterFound",
10+
"No {0} found": "No {0} found",
11+
"Searching for replacement characters...": "Searching for replacement characters...",
12+
"Checking {0}...": "Checking {0}...",
13+
"No '{0}' found in workspace": "No '{0}' found in workspace"
1014
}

l10n/ja/strings.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

package-lock.json

Lines changed: 17 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: 79 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,84 @@
11
{
2-
"name": "mojibake-inspector",
3-
"displayName": "Mojibake Inspector",
4-
"description": "Detect and highlight mojibake (replacement characters) in text files",
5-
"version": "0.0.14",
6-
"publisher": "mojibake-inspector",
7-
"repository": {
8-
"type": "git",
9-
"url": "https://github.com/ktyubeshi/mojibake-inspector"
10-
},
11-
"engines": {
12-
"vscode": "^1.48.0"
13-
},
14-
"categories": [
15-
"Other"
16-
],
17-
"activationEvents": [
18-
"onStartupFinished",
19-
"onCommand:extension.findReplacementCharacters"
20-
],
21-
"main": "./dist/extension.js",
22-
"contributes": {
23-
"commands": [
24-
{
25-
"command": "extension.findReplacementCharacters",
26-
"title": "%extension.findReplacementCharacters.title%"
27-
}
2+
"name": "mojibake-inspector",
3+
"displayName": "Mojibake Inspector",
4+
"description": "Detect and highlight mojibake (replacement characters) in text files",
5+
"version": "0.0.15",
6+
"publisher": "mojibake-inspector",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/ktyubeshi/mojibake-inspector"
10+
},
11+
"engines": {
12+
"vscode": "^1.73.0"
13+
},
14+
"categories": [
15+
"Other"
2816
],
29-
"configuration": {
30-
"title": "Mojibake Inspector",
31-
"properties": {
32-
"mojibakeInspector.excludePatterns": {
33-
"type": "array",
34-
"items": {
35-
"type": "string"
36-
},
37-
"default": [
38-
"**/.git/**",
39-
"**/node_modules/**",
40-
"**/.venv/**",
41-
"**/venv/**",
42-
"**/__pycache__/**",
43-
"**/bin/**",
44-
"**/obj/**",
45-
"**/dist/**",
46-
"**/out/**"
47-
],
48-
"description": "Patterns to exclude from workspace-wide search"
17+
"activationEvents": [
18+
"onStartupFinished"
19+
],
20+
"main": "./dist/extension.js",
21+
"l10n": "./l10n",
22+
"contributes": {
23+
"commands": [
24+
{
25+
"command": "extension.findReplacementCharacters",
26+
"title": "%extension.findReplacementCharacters.title%"
27+
}
28+
],
29+
"configuration": {
30+
"title": "Mojibake Inspector",
31+
"properties": {
32+
"mojibakeInspector.excludePatterns": {
33+
"type": "array",
34+
"items": {
35+
"type": "string"
36+
},
37+
"default": [
38+
"**/.git/**",
39+
"**/node_modules/**",
40+
"**/.venv/**",
41+
"**/venv/**",
42+
"**/__pycache__/**",
43+
"**/bin/**",
44+
"**/obj/**",
45+
"**/dist/**",
46+
"**/out/**"
47+
],
48+
"description": "Patterns to exclude from workspace-wide search"
49+
}
50+
}
4951
}
50-
}
52+
},
53+
"scripts": {
54+
"vscode:prepublish": "npm run package",
55+
"compile": "webpack",
56+
"watch": "webpack --watch",
57+
"package": "webpack --mode production --devtool hidden-source-map",
58+
"compile-tests": "tsc -p . --outDir out",
59+
"watch-tests": "tsc -p . -w --outDir out",
60+
"pretest": "npm run compile-tests && npm run compile && npm run lint",
61+
"lint": "eslint src",
62+
"test": "vscode-test",
63+
"l10n-build": "@vscode/l10n-dev build"
64+
},
65+
"devDependencies": {
66+
"@types/mocha": "^10.0.10",
67+
"@types/node": "20.x",
68+
"@types/vscode": "^1.73.0",
69+
"@typescript-eslint/eslint-plugin": "^8.17.0",
70+
"@typescript-eslint/parser": "^8.17.0",
71+
"@vscode/l10n-dev": "^0.0.35",
72+
"@vscode/test-cli": "^0.0.10",
73+
"@vscode/test-electron": "^2.4.1",
74+
"copy-webpack-plugin": "^12.0.2",
75+
"eslint": "^9.16.0",
76+
"ts-loader": "^9.5.1",
77+
"typescript": "^5.7.2",
78+
"webpack": "^5.95.0",
79+
"webpack-cli": "^5.1.4"
80+
},
81+
"dependencies": {
82+
"@vscode/l10n": "^0.0.10"
5183
}
52-
},
53-
"scripts": {
54-
"vscode:prepublish": "npm run package",
55-
"compile": "webpack",
56-
"watch": "webpack --watch",
57-
"package": "webpack --mode production --devtool hidden-source-map",
58-
"compile-tests": "tsc -p . --outDir out",
59-
"watch-tests": "tsc -p . -w --outDir out",
60-
"pretest": "npm run compile-tests && npm run compile && npm run lint",
61-
"lint": "eslint src",
62-
"test": "vscode-test",
63-
"l10n-build": "@vscode/l10n-dev build"
64-
},
65-
"devDependencies": {
66-
"@types/mocha": "^10.0.10",
67-
"@types/node": "20.x",
68-
"@types/vscode": "^1.48.0",
69-
"@typescript-eslint/eslint-plugin": "^8.17.0",
70-
"@typescript-eslint/parser": "^8.17.0",
71-
"@vscode/l10n-dev": "^0.0.35",
72-
"@vscode/test-cli": "^0.0.10",
73-
"@vscode/test-electron": "^2.4.1",
74-
"copy-webpack-plugin": "^12.0.2",
75-
"eslint": "^9.16.0",
76-
"ts-loader": "^9.5.1",
77-
"typescript": "^5.7.2",
78-
"webpack": "^5.95.0",
79-
"webpack-cli": "^5.1.4"
80-
},
81-
"l10n": "./l10n"
8284
}

src/extension.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ const mojibakeDecoration = vscode.window.createTextEditorDecorationType({
1414
// Diagnosticsのコレクションを作成
1515
const diagnosticCollection = vscode.languages.createDiagnosticCollection('mojibake');
1616

17-
// メッセージを定数として定義
17+
// メッセージを関数として定義
1818
const MOJIBAKE_CHAR = ''; // U+FFFD
19-
const DIAGNOSTIC_MESSAGE = `Detect U+FFFD (replacement character)`;
20-
const HOVER_MESSAGE = DIAGNOSTIC_MESSAGE;
19+
const getDiagnosticMessage = () => l10n.t('Detect U+FFFD (replacement character)');
20+
const getHoverMessage = getDiagnosticMessage;
2121

2222
// 除外パターンを定数として定義
2323
const DEFAULT_EXCLUDE_PATTERNS = [
@@ -42,7 +42,7 @@ export function activate(context: vscode.ExtensionContext) {
4242
context.subscriptions.push(
4343
vscode.window.onDidChangeActiveTextEditor(editor => {
4444
if (editor) {
45-
findReplacementCharacters(editor);
45+
findReplacementCharacters(editor, false);
4646
}
4747
})
4848
);
@@ -52,7 +52,7 @@ export function activate(context: vscode.ExtensionContext) {
5252
vscode.workspace.onDidChangeTextDocument(event => {
5353
const editor = vscode.window.activeTextEditor;
5454
if (editor && event.document === editor.document) {
55-
findReplacementCharacters(editor);
55+
findReplacementCharacters(editor, false);
5656
}
5757
})
5858
);
@@ -86,7 +86,7 @@ export function activate(context: vscode.ExtensionContext) {
8686
vscode.window.showInformationMessage(l10n.t('No active text editor'));
8787
return;
8888
}
89-
findReplacementCharacters(editor);
89+
findReplacementCharacters(editor, true);
9090
} else {
9191
await findReplacementCharactersInWorkspace();
9292
}
@@ -102,7 +102,7 @@ export function activate(context: vscode.ExtensionContext) {
102102
}
103103
}
104104

105-
function findReplacementCharacters(editor: vscode.TextEditor) {
105+
function findReplacementCharacters(editor: vscode.TextEditor, showMessage: boolean = false) {
106106
const text = editor.document.getText();
107107
const replacementCharRegex = /\uFFFD/g;
108108
const decorations: vscode.DecorationOptions[] = [];
@@ -117,15 +117,15 @@ function findReplacementCharacters(editor: vscode.TextEditor) {
117117
// デコレーション用
118118
const decoration = {
119119
range,
120-
hoverMessage: l10n.t(HOVER_MESSAGE)
120+
hoverMessage: getHoverMessage()
121121
};
122122
decorations.push(decoration);
123123

124124
// Diagnostic用
125125
const diagnostic = new vscode.Diagnostic(
126-
range,
127-
l10n.t(DIAGNOSTIC_MESSAGE),
128-
vscode.DiagnosticSeverity.Warning
126+
range,
127+
getDiagnosticMessage(),
128+
vscode.DiagnosticSeverity.Warning
129129
);
130130
diagnostic.code = 'mojibake';
131131
diagnostics.push(diagnostic);
@@ -137,16 +137,18 @@ function findReplacementCharacters(editor: vscode.TextEditor) {
137137
// Diagnosticsを設定
138138
diagnosticCollection.set(editor.document.uri, diagnostics);
139139

140-
// 結果を表示
141-
const count = decorations.length;
142-
if (count > 0) {
143-
vscode.window.showInformationMessage(
144-
vscode.l10n.t('extension.replacementCharacterFound', count)
145-
);
146-
} else {
147-
vscode.window.showInformationMessage(
148-
vscode.l10n.t('No {0} found', MOJIBAKE_CHAR)
149-
);
140+
// メッセージ表示はshowMessageがtrueの場合のみ
141+
if (showMessage) {
142+
const count = decorations.length;
143+
if (count > 0) {
144+
vscode.window.showInformationMessage(
145+
vscode.l10n.t('extension.replacementCharacterFound', count)
146+
);
147+
} else {
148+
vscode.window.showInformationMessage(
149+
vscode.l10n.t('No {0} found', MOJIBAKE_CHAR)
150+
);
151+
}
150152
}
151153
}
152154

@@ -185,11 +187,12 @@ async function findReplacementCharactersInWorkspace() {
185187

186188
const diagnostic = new vscode.Diagnostic(
187189
range,
188-
l10n.t(DIAGNOSTIC_MESSAGE),
190+
getDiagnosticMessage(),
189191
vscode.DiagnosticSeverity.Warning
190192
);
191193
diagnostic.code = 'mojibake';
192194
diagnostics.push(diagnostic);
195+
193196
totalCount++;
194197
}
195198

0 commit comments

Comments
 (0)