Started localizing the backend

This commit is contained in:
Elio Struyf
2023-11-02 17:17:40 +01:00
parent 966d0107d9
commit 2c026ff5e5
8 changed files with 196 additions and 30 deletions
+20 -5
View File
@@ -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 {
/**
@@ -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
});
@@ -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}`)
);
}
}
@@ -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}`)
);
}
}
@@ -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
)
);
}
}
}
+4 -2
View File
@@ -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() {
@@ -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));
}
}
}
+4 -2
View File
@@ -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 {
/**
@@ -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
+8 -6
View File
@@ -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() {
@@ -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
});
+3 -1
View File
@@ -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;
@@ -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,
+25 -14
View File
@@ -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]]`;
@@ -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;
}
@@ -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
});
@@ -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);
@@ -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) {
@@ -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 });
}
});
+100
View File
@@ -1452,6 +1452,106 @@ export enum LocalizationKey {
* Continue in the media dashboard to select the image you want to insert.
*/
panelViewPanelMediaInsert = 'panel.viewPanel.mediaInsert',
/**
* No {0} configured.
*/
commandsArticleNotificationNoTaxonomy = 'commands.article.notification.noTaxonomy',
/**
* Select your {0} to insert.
*/
commandsArticleQuickPickPlaceholder = 'commands.article.quickPick.placeholder',
/**
* Something failed while parsing the date format. Check your "{0}" setting.
*/
commandsArticleSetDateError = 'commands.article.setDate.error',
/**
* Failed to rename file: {0}
*/
commandsArticleUpdateSlugError = 'commands.article.updateSlug.error',
/**
* Cache cleared
*/
commandsCacheCleared = 'commands.cache.cleared',
/**
* Ask me anything
*/
commandsChatbotTitle = 'commands.chatbot.title',
/**
* Create content by content type
*/
commandsContentOptionContentTypeLabel = 'commands.content.option.contentType.label',
/**
* Select if you want to create new content by the available content type(s)
*/
commandsContentOptionContentTypeDescription = 'commands.content.option.contentType.description',
/**
* Create content by template
*/
commandsContentOptionTemplateLabel = 'commands.content.option.template.label',
/**
* Select if you want to create new content by the available template(s)
*/
commandsContentOptionTemplateDescription = 'commands.content.option.template.description',
/**
* Create content
*/
commandsContentQuickPickTitle = 'commands.content.quickPick.title',
/**
* Select how you want to create your new content
*/
commandsContentQuickPickPlaceholder = 'commands.content.quickPick.placeholder',
/**
* Dashboard
*/
commandsDashboardTitle = 'commands.dashboard.title',
/**
* Add media folder
*/
commandsFoldersAddMediaFolderInputBoxTitle = 'commands.folders.addMediaFolder.inputBox.title',
/**
* Which name would you like to give to your folder (use "/" to create multi-level folders)?
*/
commandsFoldersAddMediaFolderInputBoxPrompt = 'commands.folders.addMediaFolder.inputBox.prompt',
/**
* No folder name was specified.
*/
commandsFoldersAddMediaFolderNoFolderWarning = 'commands.folders.addMediaFolder.noFolder.warning',
/**
* Folder is already registered
*/
commandsFoldersCreateFolderExistsWarning = 'commands.folders.create.folderExists.warning',
/**
* Register folder
*/
commandsFoldersCreateInputTitle = 'commands.folders.create.input.title',
/**
* Which name would you like to specify for this folder?
*/
commandsFoldersCreateInputPrompt = 'commands.folders.create.input.prompt',
/**
* Folder name
*/
commandsFoldersCreateInputPlaceholder = 'commands.folders.create.input.placeholder',
/**
* Folder registered
*/
commandsFoldersCreateSuccess = 'commands.folders.create.success',
/**
* Please select the main workspace folder for Front Matter to use.
*/
commandsFoldersGetWorkspaceFolderWorkspaceFolderPickPlaceholder = 'commands.folders.getWorkspaceFolder.workspaceFolderPick.placeholder',
/**
* Folder "{0}" does not exist. Please remove it from the settings.
*/
commandsFoldersGetNotificationErrorTitle = 'commands.folders.get.notificationError.title',
/**
* Remove folder
*/
commandsFoldersGetNotificationErrorRemoveAction = 'commands.folders.get.notificationError.remove.action',
/**
* Create folder
*/
commandsFoldersGetNotificationErrorCreateAction = 'commands.folders.get.notificationError.create.action',
/**
* Template files copied.
*/