Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vscodePlugin): add i18n #1010

Merged
merged 6 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion vscodePlugin/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"dist": true // set this to false to include "dist" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
"typescript.tsc.autoDetect": "off",
"commentTranslate.targetLanguage": "en"
}
3 changes: 2 additions & 1 deletion vscodePlugin/l10n/bundle.l10n.ja.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Preview": "プレビュー",
"By": "によって"
"By": "によって",
"UnSupported": "サポートされていません"
}
5 changes: 5 additions & 0 deletions vscodePlugin/l10n/bundle.l10n.ru.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Preview": "Предварительный просмотр",
"By": "От",
"UnSupported": "Не поддерживается"
}
3 changes: 2 additions & 1 deletion vscodePlugin/l10n/bundle.l10n.zh-cn.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Preview": "预览",
"By": "通过"
"By": "通过",
"UnSupported": "不支持"
}
2 changes: 1 addition & 1 deletion vscodePlugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"homepage": "https://github.com/Tencent/cherry-markdown",
"engines": {
"vscode": "^1.58.0"
"vscode": "^1.73.0"
},
"categories": [
"Other"
Expand Down
34 changes: 34 additions & 0 deletions vscodePlugin/package.nls.ru.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"description": "Просмотрщик markdown, работающий на [cherry-markdown](https://github.com/Tencent/cherry-markdown)",
"commands.preview.title": "Просмотр в Cherry Markdown",
"usage.enum.active": "активный",
"usage.enum.only-manual": "только вручную",
"usage.description": "значения метода триггера cherry-markdown: [ активный | только вручную ]",
"theme.enum.default": "по умолчанию",
"theme.enum.dark": "темный",
"theme.enum.light": "светлый",
"theme.enum.green": "зеленый",
"theme.enum.red": "красный",
"theme.description": "тема cherry-markdown, доступные значения: [ по умолчанию | темный | светлый | зеленый | красный ]",
"uploadType.enum.None": "Нет",
"uploadType.enum.CustomUploader": "Пользовательский загрузчик",
"uploadType.enum.PicGoServer": "PicGoServer",
"uploadType.enumDescriptions.None": "не использовать загрузчик, использовать base64 для отображения изображения",
"uploadType.enumDescriptions.CustomUploader": "использовать пользовательский загрузчик",
"uploadType.enumDescriptions.PicGoServer": "использовать сервер picgo",
"uploadType.description": "режим загрузки cherry-markdown, доступные значения: [ Нет | Пользовательский загрузчик | PicGoServer ]",
"customUploader.enable.description": "включить пользовательский загрузчик",
"customUploader.url.description": "URL пользовательского загрузчика",
"customUploader.headers.description": "заголовки пользовательского загрузчика",
"customUploader.headers.key.description": "ключ заголовков пользовательского загрузчика",
"customUploader.headers.value.description": "значение заголовков пользовательского загрузчика",
"customUploader.description": "пользовательский загрузчик cherry-markdown, необходимо настроить его, если вы хотите загружать изображения / видео / аудио на свой сервер",
"picGoServer.description": "сервер picgo cherry-markdown, необходимо настроить его, если вы хотите загружать изображения / видео / аудио на сервер picgo",
"backfillImageProps.enum.isBorder": "с границей",
"backfillImageProps.enum.isNotBorder": "без границы",
"backfillImageProps.enum.isRadius": "с радиусом",
"backfillImageProps.enumDescriptions.isBorder": "Добавить ли границу к изображению",
"backfillImageProps.enumDescriptions.isShadow": "Добавить ли тень к изображению",
"backfillImageProps.enumDescriptions.isRadius": "Добавить ли закругленные углы к изображению",
"backfillImageProps.description": "свойства обратного заполнения изображения cherry-markdown, необходимо настроить их, если вы хотите заполнить свойства изображения"
}
7 changes: 4 additions & 3 deletions vscodePlugin/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ const getMarkdownFileInfo = () => {
}

currentTitle = currentTitle
? `${vscode.l10n.t('Preview')} ${currentTitle} ${vscode.l10n.t('By')} cherry-markdown`
: '不支持当前文件 by cherry-markdown';
? `${vscode.l10n.t('Preview')} ${currentTitle} ${vscode.l10n.t('By')} Cherry Markdown`
: `${vscode.l10n.t('UnSupported')} ${vscode.l10n.t('By')} Cherry Markdown`;
const theme = cherryTheme
? cherryTheme
: vscode.workspace.getConfiguration('cherryMarkdown').get('Theme');
Expand Down Expand Up @@ -124,8 +124,9 @@ const initCherryPanel = () => {
],
},
);
console.log('vscode.env.language', vscode.env.language);
cherryPanel.webview.html = getWebviewContent(
mdInfo,
{ ...mdInfo, vscodeLanguage: vscode.env.language },
cherryPanel,
extensionPath,
);
Expand Down
28 changes: 25 additions & 3 deletions vscodePlugin/web-resources/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ const customMenuFont = Cherry.createMenuHook('字体样式', {

/** 处理 a 链接跳转问题 */
const onClickLink = (e, target) => {


// 这里不能直接使用 target.href,因为本地相对文件地址会被vscode转成`webview://`协议
const href = target.attributes?.href.value;

Expand Down Expand Up @@ -292,8 +290,32 @@ function isHttpUrl(url) {
return /https?:\/\//.test(url);
}

/**
* [vscode language](https://code.visualstudio.com/docs/getstarted/locales#_available-locales);
* [cherry language](https://github.com/Tencent/cherry-markdown/wiki/%E5%A4%9A%E8%AF%AD%E8%A8%80);
* */
const languageIdentifiers = {
en: 'en_US', // English (US)
'zh-cn': 'zh_CN', // Simplified Chinese
'zh-tw': '繁体中文', // Traditional Chinese
fr: '法语', // French
de: '德语', // German
it: '意大利语', // Italian
es: '西班牙语', // Spanish
ja: 'ja_JP', // Japanese
ko: '韩国人', // Korean
ru: 'ru_RU', // Russian
'pt-br': '葡萄牙语(巴西)', // Portuguese (Brazil)
tr: '土耳其', // Turkish
pl: '抛光', // Polish
cs: '捷克语', // Czech
hu: '匈牙利', // Hungarian
};
RSS1102 marked this conversation as resolved.
Show resolved Hide resolved

const mdInfo = JSON.parse(document.getElementById('markdown-info').value);
const config = Object.assign({}, basicConfig, { value: mdInfo.text });
const locale = languageIdentifiers[mdInfo.vscodeLanguage] || 'zh_CN';

const config = Object.assign({}, basicConfig, { value: mdInfo.text, locale });
// eslint-disable-next-line new-cap, no-undef
const cherry = new Cherry(config);
// eslint-disable-next-line no-undef
Expand Down
Loading