From 2c026ff5e56d7760dac9c70a791a8f70987ac2a4 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Thu, 2 Nov 2023 17:17:40 +0100 Subject: [PATCH] Started localizing the backend --- l10n/bundle.l10n.json | 32 +++++++++ src/commands/Article.ts | 25 +++++-- src/commands/Cache.ts | 6 +- src/commands/Chatbot.ts | 6 +- src/commands/Content.ts | 14 ++-- src/commands/Dashboard.ts | 4 +- src/commands/Folders.ts | 39 ++++++---- src/localization/localization.enum.ts | 100 ++++++++++++++++++++++++++ 8 files changed, 196 insertions(+), 30 deletions(-) diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index dc967c25..bef5e03f 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -457,5 +457,37 @@ "panel.viewPanel.mediaInsert": "Continue in the media dashboard to select the image you want to insert.", + "commands.article.notification.noTaxonomy": "No {0} configured.", + "commands.article.quickPick.placeholder": "Select your {0} to insert.", + "commands.article.setDate.error": "Something failed while parsing the date format. Check your \"{0}\" setting.", + "commands.article.updateSlug.error": "Failed to rename file: {0}", + + "commands.cache.cleared": "Cache cleared", + + "commands.chatbot.title": "Ask me anything", + + "commands.content.option.contentType.label": "Create content by content type", + "commands.content.option.contentType.description": "Select if you want to create new content by the available content type(s)", + "commands.content.option.template.label": "Create content by template", + "commands.content.option.template.description": "Select if you want to create new content by the available template(s)", + "commands.content.quickPick.title": "Create content", + "commands.content.quickPick.placeholder": "Select how you want to create your new content", + + "commands.dashboard.title": "Dashboard", + + "commands.folders.addMediaFolder.inputBox.title": "Add media folder", + "commands.folders.addMediaFolder.inputBox.prompt": "Which name would you like to give to your folder (use \"/\" to create multi-level folders)?", + "commands.folders.addMediaFolder.noFolder.warning": "No folder name was specified.", + "commands.folders.create.folderExists.warning": "Folder is already registered", + "commands.folders.create.input.title": "Register folder", + "commands.folders.create.input.prompt": "Which name would you like to specify for this folder?", + "commands.folders.create.input.placeholder": "Folder name", + "commands.folders.create.success": "Folder registered", + "commands.folders.getWorkspaceFolder.workspaceFolderPick.placeholder": "Please select the main workspace folder for Front Matter to use.", + "commands.folders.get.notificationError.title": "Folder \"{0}\" does not exist. Please remove it from the settings.", + "commands.folders.get.notificationError.remove.action": "Remove folder", + "commands.folders.get.notificationError.create.action": "Create folder", + "listeners.dashboard.settingsListener.triggerTemplate.notification": "Template files copied." + } \ No newline at end of file diff --git a/src/commands/Article.ts b/src/commands/Article.ts index 44f8d004..f6e36e05 100644 --- a/src/commands/Article.ts +++ b/src/commands/Article.ts @@ -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 + ) + ); } } } diff --git a/src/commands/Cache.ts b/src/commands/Cache.ts index aafaa7f2..65eb5306 100644 --- a/src/commands/Cache.ts +++ b/src/commands/Cache.ts @@ -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)); } } } diff --git a/src/commands/Chatbot.ts b/src/commands/Chatbot.ts index c598d10b..856e3424 100644 --- a/src/commands/Chatbot.ts +++ b/src/commands/Chatbot.ts @@ -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 diff --git a/src/commands/Content.ts b/src/commands/Content.ts index 6c4ef060..b5201a24 100644 --- a/src/commands/Content.ts +++ b/src/commands/Content.ts @@ -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 }); diff --git a/src/commands/Dashboard.ts b/src/commands/Dashboard.ts index 342b747f..a1286500 100644 --- a/src/commands/Dashboard.ts +++ b/src/commands/Dashboard.ts @@ -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, diff --git a/src/commands/Folders.ts b/src/commands/Folders.ts index 68000f43..10f8513b 100644 --- a/src/commands/Folders.ts +++ b/src/commands/Folders.ts @@ -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 }); } }); diff --git a/src/localization/localization.enum.ts b/src/localization/localization.enum.ts index 076205b5..3f23a660 100644 --- a/src/localization/localization.enum.ts +++ b/src/localization/localization.enum.ts @@ -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. */