Skip to content

Commit

Permalink
feat: use QuickPick to input locale (#8)
Browse files Browse the repository at this point in the history
instead of manually type it.
  • Loading branch information
MaikoTan authored Jan 22, 2021
1 parent 4534d65 commit 62fdd62
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions src/translateTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,46 @@ export const translateTimeline = async () => {
let locale = vscode.workspace.getConfiguration().get("cactbot.timeline.defaultLocale");

if (!(typeof locale === "string" && locale)) {
locale = await vscode.window.showInputBox({
placeHolder: 'Input a locale...',
validateInput: (value) => {
const validLocales = ["de", "fr", "ja", "cn", "ko"];
if (validLocales.includes(value)) {
return null;
}
return `Locale should be one of [${validLocales.join(", ")}]`;
},
});
locale = await vscode.window.showQuickPick(
[
{
label: 'de',
description: 'German',
detail: 'Deutsch',
},
{
label: 'fr',
description: 'French',
detail: 'français',
},
{
label: 'ja',
description: 'Japanese',
detail: '日本語',
},
{
label: 'cn',
description: 'Chinese',
detail: '中文',
},
{
label: 'ko',
description: 'Korean',
detail: '한국어',
},
],
{
placeHolder: 'Input a locale...',
canPickMany: false,
}
);
}

if (!locale) {
return;
}

const uri = vscode.Uri.parse('cactbot-timeline:' + filename + "?" + locale);
const uri = vscode.Uri.parse('cactbot-timeline:' + filename + "?" + (locale as vscode.QuickPickItem).label);
const translatedDocument = await vscode.workspace.openTextDocument(uri); // calls back into the provider
await vscode.window.showTextDocument(translatedDocument, { preview: false });
await vscode.languages.setTextDocumentLanguage(translatedDocument, "cactbot-timeline");
Expand Down

0 comments on commit 62fdd62

Please sign in to comment.