-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multilingual translation support (#5)
* fix: Error handling when API KEY is empty * feat: Multi-language support * docs: update README.md
- Loading branch information
Showing
22 changed files
with
112 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,46 @@ | ||
import { isEmpty } from "lodash"; | ||
import * as vscode from "vscode"; | ||
import { setApiKeyCommand } from "."; | ||
import { GitExtension } from "../types/vscode"; | ||
|
||
import { getDeepLApiKey } from "../utils/getDeepLApiKey"; | ||
import { getTranslatedCommitMessage } from "../utils/getTranslatedCommitMessage"; | ||
import { | ||
activateGitExtension, | ||
getSingleRepository, | ||
isGitExtensionValidate, | ||
} from "../utils/gitExtension"; | ||
import validateString from "../utils/validateString"; | ||
import { isGitExtensionValid, activateGitExtension, getSingleRepository } from "../utils/git"; | ||
import getTranslatedCommitMessage from "../utils/getTranslatedCommitMessage"; | ||
import getDeepLApiKey from "../utils/getDeepLApiKey"; | ||
import isStringValid from "../utils/isStringValid"; | ||
import { isEmpty } from "lodash"; | ||
import getGitExtension from "../utils/git/getGitExtension"; | ||
|
||
export async function translateCommitCommand() { | ||
/** 1. (success) check if git extension is valid */ | ||
const gitExtension = | ||
vscode.extensions.getExtension<GitExtension>("vscode.git"); | ||
if (!isGitExtensionValidate(gitExtension)) { | ||
/** 1. check if git extension is valid & activate git extension*/ | ||
const gitExtension = getGitExtension(); | ||
if (!isGitExtensionValid(gitExtension)) { | ||
return; | ||
} | ||
await activateGitExtension(gitExtension); | ||
|
||
/** 2. (success ?) check if apiKey is valid */ | ||
let apikey: string | undefined = getDeepLApiKey(); | ||
if (!validateString(apikey)) { | ||
apikey = await setApiKeyCommand(); | ||
// vscode.window.showInformationMessage(apikey as string); | ||
// await vscode.commands.executeCommand(Commands.SetApiKey); | ||
/** 2. check if apiKey exists*/ | ||
let apiKey = getDeepLApiKey(); | ||
if (!isStringValid(apiKey)) { | ||
apiKey = await setApiKeyCommand(); | ||
} | ||
|
||
// if (!isValidateApiKey()) { | ||
// vscode.window.showInformationMessage("api key is invalid"); | ||
// return; | ||
// vscode.window.showInformationMessage(apikey as string); | ||
// await vscode.commands.executeCommand(Commands.SetApiKey); | ||
// } | ||
if (!isStringValid(apiKey)) { | ||
return; | ||
} | ||
|
||
/** 3. (success) get repository from git */ | ||
/** 3. get repository from git */ | ||
const repository = getSingleRepository(gitExtension); | ||
|
||
/** 4. (success) get commit from repository */ | ||
/** 4. get commit from repository */ | ||
const commit = repository.inputBox.value; | ||
if (isEmpty(commit)) { | ||
vscode.window.showErrorMessage("Commit message is empty"); | ||
return; | ||
} | ||
/** 5. (success) translate commit message with Deepl api */ | ||
|
||
/** 5. translate commit message with Deepl api */ | ||
const translatedMessage = await getTranslatedCommitMessage({ | ||
apikey: apikey as string, | ||
commit, | ||
apiKey, | ||
}); | ||
|
||
/** 6. (success) log translated commit */ | ||
/** 6. log translated commit */ | ||
repository.inputBox.value = translatedMessage; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/utils/getConfiguration.ts → src/utils/configuration/getConfiguration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import * as vscode from "vscode"; | ||
|
||
export function getDeepLApiKey() { | ||
const apiKey = vscode.workspace | ||
.getConfiguration("commit-translator.deepl") | ||
.get<string>("apiKey"); | ||
import { ApiKey } from "../constants/api"; | ||
import { getConfiguration } from "./configuration/getConfiguration"; | ||
|
||
export default function getDeepLApiKey(): string | undefined { | ||
const apiKey = getConfiguration().get<string | undefined>(ApiKey); | ||
return apiKey; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as vscode from "vscode"; | ||
import { GitExtension } from "../../types/vscode"; | ||
|
||
export async function activateGitExtension(gitExtension: vscode.Extension<GitExtension>) { | ||
if (!gitExtension.isActive) { | ||
await gitExtension.activate(); | ||
} | ||
if (!gitExtension.isActive) { | ||
throw new Error("Git extension is not active"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as vscode from "vscode"; | ||
import { GitExtension } from "../../types/vscode"; | ||
|
||
export default function getGitExtension() { | ||
return vscode.extensions.getExtension<GitExtension>("vscode.git"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as vscode from "vscode"; | ||
import { isEmpty } from "lodash"; | ||
import { GitExtension, Repository } from "../../types/vscode"; | ||
|
||
export function getSingleRepository(gitExtension: vscode.Extension<GitExtension>): Repository { | ||
const repositories = gitExtension.exports.getAPI(1).repositories; | ||
|
||
if (isEmpty(repositories)) { | ||
throw new Error("No repositories found"); | ||
} | ||
return repositories[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./activateGitExtension"; | ||
export * from "./getSingleRepository"; | ||
export * from "./isGitExtensionValid"; | ||
export * from "./getGitExtension"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as vscode from "vscode"; | ||
import { GitExtension } from "../../types/vscode"; | ||
|
||
export function isGitExtensionValid( | ||
gitExtension: vscode.Extension<GitExtension> | undefined | ||
): gitExtension is vscode.Extension<GitExtension> { | ||
if (!gitExtension) { | ||
vscode.window.showErrorMessage("Git extension is not installed."); | ||
return false; | ||
} | ||
return true; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { isEmpty } from "lodash"; | ||
|
||
export default function isStringValid(text: string | null | undefined): text is string { | ||
return Boolean(text) && !isEmpty(text); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters