Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:estruyf/vscode-front-matter into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Nov 13, 2023
2 parents 2e536a4 + 739dffe commit 8684f32
Show file tree
Hide file tree
Showing 52 changed files with 1,969 additions and 407 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### ✨ New features

- Localization implemented for the whole extension

### 🎨 Enhancements

- [#273](https://github.com/estruyf/vscode-front-matter/issues/273): Allow single value arrays to be set as a string with the `singleValueAsString` field property
Expand All @@ -25,6 +27,8 @@
- [#694](https://github.com/estruyf/vscode-front-matter/issues/694): Start terminal session from the folder where the `frontmatter.json` file is located
- [#696](https://github.com/estruyf/vscode-front-matter/issues/696): Close the local server terminal on restart
- [#699](https://github.com/estruyf/vscode-front-matter/issues/699): Changing border theme variable for the dashboard header
- [#703](https://github.com/estruyf/vscode-front-matter/issues/703): Fix retrieval of Astro Collections for `pnpm` projects
- [#704](https://github.com/estruyf/vscode-front-matter/issues/704): Fix `zod` schema script for optional fields

## [9.3.1] - 2023-10-27

Expand Down
251 changes: 249 additions & 2 deletions l10n/bundle.l10n.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions scripts/generate-localization-enum.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const jsoncParser = require('jsonc-parser');

const camlCase = (str) => {
const words = str.split('.');
Expand All @@ -15,12 +16,14 @@ const camlCase = (str) => {
const enFile = fs.readFileSync(path.join(__dirname, '../l10n/bundle.l10n.json'), 'utf8');

// Parse the EN file
const en = JSON.parse(enFile);
const en = jsoncParser.parse(enFile);

const keys = Object.keys(en);

// Create an enum file
const enumFile = fs.createWriteStream(path.join(__dirname, '../src/localization/localization.enum.ts'));
const enumFile = fs.createWriteStream(
path.join(__dirname, '../src/localization/localization.enum.ts')
);

// Write the enum file header
enumFile.write(`export enum LocalizationKey {\n`);
Expand All @@ -38,4 +41,4 @@ const camlCase = (str) => {

// Close the enum file
enumFile.close();
})();
})();
25 changes: 20 additions & 5 deletions src/commands/Article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { NavigationType } from '../dashboardWebView/models';
import { processKnownPlaceholders } from '../helpers/PlaceholderHelper';
import { Position } from 'vscode';
import { SNIPPET } from '../constants/Snippet';
import * as l10n from '@vscode/l10n';
import { LocalizationKey } from '../localization';

export class Article {
/**
Expand Down Expand Up @@ -80,12 +82,20 @@ export class Article {
}

if (options.length === 0) {
Notifications.info(`No ${type === TaxonomyType.Tag ? 'tags' : 'categories'} configured.`);
Notifications.info(
l10n.t(
LocalizationKey.commandsArticleNotificationNoTaxonomy,
type === TaxonomyType.Tag ? 'tags' : 'categories'
)
);
return;
}

const selectedOptions = await vscode.window.showQuickPick(options, {
placeHolder: `Select your ${type === TaxonomyType.Tag ? 'tags' : 'categories'} to insert`,
placeHolder: l10n.t(
LocalizationKey.commandsArticleQuickPickPlaceholder,
type === TaxonomyType.Tag ? 'tags' : 'categories'
),
canPickMany: true,
ignoreFocusOut: true
});
Expand Down Expand Up @@ -117,7 +127,7 @@ export class Article {
ArticleHelper.update(editor, article);
} catch (e) {
Notifications.error(
`Something failed while parsing the date format. Check your "${CONFIG_KEY}${SETTING_DATE_FORMAT}" setting.`
l10n.t(LocalizationKey.commandsArticleSetDateError, `${CONFIG_KEY}${SETTING_DATE_FORMAT}`)
);
}
}
Expand Down Expand Up @@ -180,7 +190,7 @@ export class Article {
return cloneArticle;
} catch (e: unknown) {
Notifications.error(
`Something failed while parsing the date format. Check your "${CONFIG_KEY}${SETTING_DATE_FORMAT}" setting.`
l10n.t(LocalizationKey.commandsArticleSetDateError, `${CONFIG_KEY}${SETTING_DATE_FORMAT}`)
);
}
}
Expand Down Expand Up @@ -292,7 +302,12 @@ export class Article {
overwrite: false
});
} catch (e: unknown) {
Notifications.error(`Failed to rename file: ${(e as Error).message || e}`);
Notifications.error(
l10n.t(
LocalizationKey.commandsArticleUpdateSlugError,
((e as Error).message || e) as string
)
);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/commands/Cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { commands } from 'vscode';
import { COMMAND_NAME, ExtensionState } from '../constants';
import { Extension, Logger, Notifications } from '../helpers';
import * as l10n from '@vscode/l10n';
import { LocalizationKey } from '../localization';

export class Cache {
public static async registerCommands() {
Expand Down Expand Up @@ -28,9 +30,9 @@ export class Cache {
await ext.setState(ExtensionState.Settings.Extends, undefined, 'workspace', true);

if (showNotification) {
Notifications.info('Cache cleared');
Notifications.info(l10n.t(LocalizationKey.commandsCacheCleared));
} else {
Logger.info('Cache cleared');
Logger.info(l10n.t(LocalizationKey.commandsCacheCleared));
}
}
}
6 changes: 4 additions & 2 deletions src/commands/Chatbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { Telemetry } from './../helpers/Telemetry';
import { TelemetryEvent, PreviewCommands, GeneralCommands } from './../constants';
import { join } from 'path';
import { commands, Uri, ViewColumn, window } from 'vscode';
import { Extension, Settings } from '../helpers';
import { Extension } from '../helpers';
import { WebviewHelper } from '@estruyf/vscode';
import { getLocalizationFile } from '../utils/getLocalizationFile';
import * as l10n from '@vscode/l10n';
import { LocalizationKey } from '../localization';

export class Chatbot {
/**
Expand All @@ -14,7 +16,7 @@ export class Chatbot {
// Create the preview webview
const webView = window.createWebviewPanel(
'frontMatterChatbot',
'Front Matter AI - Ask me anything',
`Front Matter AI - ${l10n.t(LocalizationKey.commandsChatbotTitle)}`,
{
viewColumn: ViewColumn.Beside,
preserveFocus: true
Expand Down
14 changes: 8 additions & 6 deletions src/commands/Content.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { commands, QuickPickItem, window } from 'vscode';
import { COMMAND_NAME, SETTING_TEMPLATES_ENABLED } from '../constants';
import { Settings } from '../helpers';
import * as l10n from '@vscode/l10n';
import { LocalizationKey } from '../localization';

export class Content {
public static async create() {
Expand All @@ -12,18 +14,18 @@ export class Content {

const options: QuickPickItem[] = [
{
label: 'Create content by content type',
description: 'Select if you want to create new content by the available content type(s)'
label: l10n.t(LocalizationKey.commandsContentOptionContentTypeLabel),
description: l10n.t(LocalizationKey.commandsContentOptionContentTypeDescription)
},
{
label: 'Create content by template',
description: 'Select if you want to create new content by the available template(s)'
label: l10n.t(LocalizationKey.commandsContentOptionTemplateLabel),
description: l10n.t(LocalizationKey.commandsContentOptionTemplateDescription)
} as QuickPickItem
];

const selectedOption = await window.showQuickPick(options, {
title: 'Create content',
placeHolder: `Select how you want to create your new content`,
title: l10n.t(LocalizationKey.commandsContentQuickPickTitle),
placeHolder: l10n.t(LocalizationKey.commandsContentQuickPickPlaceholder),
canPickMany: false,
ignoreFocusOut: true
});
Expand Down
4 changes: 3 additions & 1 deletion src/commands/Dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
import { MediaListener as PanelMediaListener } from '../listeners/panel';
import { GitListener, ModeListener } from '../listeners/general';
import { Folders } from './Folders';
import * as l10n from '@vscode/l10n';
import { LocalizationKey } from '../localization';

export class Dashboard {
private static webview: WebviewPanel | null = null;
Expand Down Expand Up @@ -119,7 +121,7 @@ export class Dashboard {
// Create the preview webview
Dashboard.webview = window.createWebviewPanel(
'frontMatterDashboard',
'FrontMatter Dashboard',
`Front Matter ${l10n.t(LocalizationKey.commandsDashboardTitle)}`,
ViewColumn.One,
{
enableScripts: true,
Expand Down
39 changes: 25 additions & 14 deletions src/commands/Folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { Telemetry } from '../helpers/Telemetry';
import { glob } from 'glob';
import { mkdirAsync } from '../utils/mkdirAsync';
import { existsAsync } from '../utils';
import * as l10n from '@vscode/l10n';
import { LocalizationKey } from '../localization';

export const WORKSPACE_PLACEHOLDER = `[[workspace]]`;

Expand Down Expand Up @@ -57,15 +59,15 @@ export class Folders {
}

const folderName = await window.showInputBox({
title: `Add media folder`,
prompt: `Which name would you like to give to your folder (use "/" to create multi-level folders)?`,
title: l10n.t(LocalizationKey.commandsFoldersAddMediaFolderInputBoxTitle),
prompt: l10n.t(LocalizationKey.commandsFoldersAddMediaFolderInputBoxPrompt),
value: startPath,
ignoreFocusOut: true,
placeHolder: `${format(new Date(), `yyyy/MM`)}`
});

if (!folderName) {
Notifications.warning(`No folder name was specified.`);
Notifications.warning(l10n.t(LocalizationKey.commandsFoldersAddMediaFolderNoFolderWarning));
return;
}

Expand Down Expand Up @@ -126,15 +128,15 @@ export class Folders {
);

if (exists) {
Notifications.warning(`Folder is already registered`);
Notifications.warning(l10n.t(LocalizationKey.commandsFoldersCreateFolderExistsWarning));
return;
}

if (!folderName) {
folderName = await window.showInputBox({
title: `Register folder`,
prompt: `Which name would you like to specify for this folder?`,
placeHolder: `Folder name`,
title: l10n.t(LocalizationKey.commandsFoldersCreateInputTitle),
prompt: l10n.t(LocalizationKey.commandsFoldersCreateInputPrompt),
placeHolder: l10n.t(LocalizationKey.commandsFoldersCreateInputPlaceholder),
value: basename(folder.fsPath),
ignoreFocusOut: true
});
Expand All @@ -154,7 +156,7 @@ export class Folders {
folders = uniqBy(folders, (f) => f.path);
await Folders.update(folders);

Notifications.info(`Folder registered`);
Notifications.info(l10n.t(LocalizationKey.commandsFoldersCreateSuccess));

Telemetry.send(TelemetryEvent.registerFolder);

Expand Down Expand Up @@ -245,7 +247,9 @@ export class Folders {
if (!projectFolder) {
window
.showWorkspaceFolderPick({
placeHolder: `Please select the main workspace folder for Front Matter to use.`
placeHolder: l10n.t(
LocalizationKey.commandsFoldersGetWorkspaceFolderWorkspaceFolderPickPlaceholder
)
})
.then(async (selectedFolder) => {
if (selectedFolder) {
Expand Down Expand Up @@ -378,14 +382,21 @@ export class Folders {
} else {
if (folderPath && !existsSync(folderPath)) {
Notifications.errorShowOnce(
`Folder "${folder.title} (${folder.path})" does not exist. Please remove it from the settings.`,
'Remove folder',
'Create folder'
l10n.t(
LocalizationKey.commandsFoldersGetNotificationErrorTitle,
`${folder.title} (${folder.path})`
),
l10n.t(LocalizationKey.commandsFoldersGetNotificationErrorRemoveAction),
l10n.t(LocalizationKey.commandsFoldersGetNotificationErrorCreateAction)
).then((answer) => {
if (answer === 'Remove folder') {
if (
answer === l10n.t(LocalizationKey.commandsFoldersGetNotificationErrorRemoveAction)
) {
const folders = Folders.get();
Folders.update(folders.filter((f) => f.path !== folder.path));
} else if (answer === 'Create folder') {
} else if (
answer === l10n.t(LocalizationKey.commandsFoldersGetNotificationErrorCreateAction)
) {
mkdirAsync(folderPath as string, { recursive: true });
}
});
Expand Down
8 changes: 6 additions & 2 deletions src/commands/Preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { WebviewHelper } from '@estruyf/vscode';
import { Folders } from './Folders';
import { ParsedFrontMatter } from '../parsers';
import { getLocalizationFile } from '../utils/getLocalizationFile';
import * as l10n from '@vscode/l10n';
import { LocalizationKey } from '../localization';

export class Preview {
public static filePath: string | undefined = undefined;
Expand Down Expand Up @@ -71,7 +73,9 @@ export class Preview {
// Create the preview webview
const webView = window.createWebviewPanel(
'frontMatterPreview',
article?.data?.title ? `Preview: ${article?.data?.title}` : 'FrontMatter Preview',
article?.data?.title
? l10n.t(LocalizationKey.commandsPreviewPanelTitle, article?.data.title)
: 'Front Matter Preview',
{
viewColumn: ViewColumn.Beside,
preserveFocus: true
Expand Down Expand Up @@ -393,7 +397,7 @@ export class Preview {
const folderNames = crntFolders.map((folder) => folder.title);
const selectedFolderName = await window.showQuickPick(folderNames, {
canPickMany: false,
title: 'Select the folder of the article to preview'
title: l10n.t(LocalizationKey.commandsPreviewAskUserToPickFolderTitle)
});

if (selectedFolderName) {
Expand Down
14 changes: 10 additions & 4 deletions src/commands/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
} from '../constants';
import { SettingsListener } from '../listeners/dashboard';
import { existsAsync, writeFileAsync } from '../utils';
import * as l10n from '@vscode/l10n';
import { LocalizationKey } from '../localization';

export class Project {
private static content = `---
Expand Down Expand Up @@ -66,7 +68,7 @@ categories: []
if (sampleTemplate !== undefined) {
await Project.createSampleTemplate();
} else {
Notifications.info('Project initialized successfully.');
Notifications.info(l10n.t(LocalizationKey.commandsProjectInitializeSuccess));
}

// Initialize the media library
Expand All @@ -89,18 +91,22 @@ categories: []
} catch (error: unknown) {
const err = error as Error;
Logger.error(`Project::init: ${err?.message || err}`);
Notifications.error(`Sorry, something went wrong - ${err?.message || err}`);
Notifications.errorWithOutput(l10n.t(LocalizationKey.commonError));
}
}

/**
* Project switcher
* @returns
*/
public static async switchProject() {
const projects = Settings.getProjects();
const project = await window.showQuickPick(
projects.map((p) => p.name),
{
canPickMany: false,
ignoreFocusOut: true,
title: 'Select a project to switch to'
title: l10n.t(LocalizationKey.commandsProjectSwitchProjectTitle)
}
);

Expand Down Expand Up @@ -136,7 +142,7 @@ categories: []
await writeFileAsync(article.fsPath, Project.content, {
encoding: 'utf-8'
});
Notifications.info('Sample template created.');
Notifications.info(l10n.t(LocalizationKey.commandsProjectCreateSampleTemplateInfo));
}
}

Expand Down
Loading

0 comments on commit 8684f32

Please sign in to comment.