Skip to content

Commit

Permalink
🐛 Rewrite localization & welcome (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemmingh committed Jan 24, 2021
1 parent 115935f commit 08c6f57
Show file tree
Hide file tree
Showing 16 changed files with 491 additions and 220 deletions.
7 changes: 5 additions & 2 deletions .gitignore
@@ -1,9 +1,12 @@
out
node_modules
VERSION
*.vsix
ROADMAP.md
*.log
/.vscode-test
dist
tmp
tmp

# The welcome materials
/welcome/**
/changes.md
4 changes: 3 additions & 1 deletion .vscodeignore
Expand Up @@ -13,8 +13,10 @@ src/
# Configuration files
.github/
.vscode/
VERSION
.gitignore
tsconfig.json
package-json.lock
webpack.config.js

# The welcome flag file
welcome/WELCOMED
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -439,7 +439,7 @@
]
},
"scripts": {
"vscode:prepublish": "webpack --mode production",
"vscode:prepublish": "node ./tools/prepublish.js",
"compile": "webpack --mode none",
"watch": "webpack --mode none --watch",
"test": "tsc -p ./ && node ./out/test/runTest.js",
Expand Down
25 changes: 7 additions & 18 deletions package.nls.ja.json
Expand Up @@ -15,7 +15,6 @@
"config.toc.unorderedList.marker.description": "目次(TOC)に `-` `*` `+` のどれを使用するか (順序なしリストの場合)",
"config.toc.plaintext.description": "目次(TOC)にリンクなし(プレーンテキスト)を使用する",
"config.toc.updateOnSave.description": "目次(TOC)を保存時に自動更新",
"config.toc.githubCompatibility.description": "目次(TOC)のGitHub互換",
"config.toc.downcaseLink.description": "目次(TOC)用リンクを小文字化する",
"config.toc.omittedFromToc.description": "プロジェクトファイルの目次(TOC)で除外する見出しの一覧(例. {\"README.md\": [\"# Introduction\"]})",
"config.list.indentationSize.description": "異なる構文で異なるインデント幅を使用するかどうか(これは、生成された目次・TOCにも影響します)",
Expand All @@ -34,23 +33,13 @@
"config.print.onFileSave.description": "ファイル保存時に現在のドキュメントをHTMLへ出力する",
"config.print.validateUrls.description": "出力時のURL検証の有効化/無効化",
"config.print.theme": "出力されたHTMLのテーマ",
"config.syntax.decorations.description": "Add syntax decorations",
"config.syntax.plainTheme.description": "`extension.syntax.decorations`が有効な場合にのみ作用させる",
"config.katex.macros.description": "ユーザ定義のKaTeXマクロ",
"config.completion.root": "Pathの自動補完におけるルートフォルダ",
"showMe": "表示する",
"dismiss": "却下",
"noValidMarkdownFile": "有効なMarkdownファイルがありません",
"printing": "出力中",
"to": "",
"unableToReadFile": "ファイルを読み取れません",
"revertingToImagePaths": "base64エンコードを画像Pathに戻す",
"customStyle": "カスタムスタイル",
"notFound": "が見つかりません。",
"cannotUseBuiltinSlugifyFunc": "VSCode組み込みのslugify関数が使用できません。GitHubのslugify関数にフォールバックします。VSCodeを最新バージョンに更新するか、 `githubCompatibility`を`true`に設定してください",
"1.3.0 msg": "エキサイティングな機能をご紹介! 自動で番号再割り当てできる順序付きリスト。",
"1.4.0 msg": "『Markdown-All-in-One v1.4.0』におけるたくさんの新機能",
"1.5.0 msg": "お久しぶりです。『Markdown-All-in-One v1.5.0』へようこそ。",
"2.1.0 msg": "『Markdown All in One』v2.1.0! リンクとしてURLを貼り付けしたり、マルチカーソルのサポートなど。",
"2.4.0 msg": "『Markdown All in One』v2.4.0! 新コマンド`toggleList`とKaTeXマクロのサポート。"
"ui.exporting.messageCustomCssNotFound": "'{0}' が見つかりません。",
"ui.exporting.messageExportingInProgress": "{1} 出力中: '{0}'",
"ui.exporting.messageRevertingToImagePaths": "base64エンコードを画像Pathに戻す。",
"ui.general.messageNoValidMarkdownFile": "有効な Markdown ファイルがありません。",
"ui.general.messageUnableToReadFile": "ファイルを読み取れません: '{0}'",
"ui.welcome.buttonDismiss": "却下",
"ui.welcome.buttonOpenLocal": "表示する"
}
23 changes: 7 additions & 16 deletions package.nls.json
Expand Up @@ -45,20 +45,11 @@
"config.toc.slugifyMode.description": "The method to generate heading ID. This affects **links to headings** in **TOC**, **code completion**, and **printing**.",
"config.toc.unorderedList.marker.description": "Use `-`, `*`, or `+` in the table of contents (for **unordered** list).",
"config.toc.updateOnSave.description": "Auto update TOC on save.",
"showMe": "Show Me",
"dismiss": "Dismiss",
"noValidMarkdownFile": "No valid Markdown file",
"printing": "Printing",
"to": "to",
"unableToReadFile": "Unable to read file",
"revertingToImagePaths": "Reverting to image paths instead of base64 encoding",
"customStyle": "Custom style",
"notFound": " not found.",
"cannotUseBuiltinSlugifyFunc": "Cannot use VSCode built-in slugify function, fall back to GitHub slugify funtion. Try to update VSCode to the latest version or set setting `githubCompatibility` to `true`",
"1.3.0 msg": "Introduce an exciting feature! Auto renumbering ordered list.",
"1.4.0 msg": "Many new features of Markdown-All-in-One v1.4.0",
"1.5.0 msg": "Long time no see. Welcome to Markdown-All-in-One v1.5.0.",
"2.1.0 msg": "Markdown All in One v2.1.0! Paste URL as link, multi-cursor support, and more.",
"2.4.0 msg": "Markdown All in One v2.4.0! New command 'toggleList' and KaTeX macros support.",
"3.0.0 msg": "Markdown All in One v3.0.0! New command 'add section numbers' and better compatibility with other Markdown syntax extensions."
"ui.exporting.messageCustomCssNotFound": "Custom CSS '{0}' not found.",
"ui.exporting.messageExportingInProgress": "Printing '{0}' to {1} ...",
"ui.exporting.messageRevertingToImagePaths": "Reverting to image paths instead of base64 encoding.",
"ui.general.messageNoValidMarkdownFile": "No valid Markdown file.",
"ui.general.messageUnableToReadFile": "Unable to read file '{0}'.",
"ui.welcome.buttonDismiss": "Dismiss",
"ui.welcome.buttonOpenLocal": "Read"
}
23 changes: 7 additions & 16 deletions package.nls.zh-cn.json
Expand Up @@ -37,20 +37,11 @@
"config.toc.slugifyMode.description": "生成标题 ID 的方法。该设置影响**目录**、**代码自动补全**、**打印**中**指向标题的链接**。",
"config.toc.unorderedList.marker.description": "在目录中使用 `-`,`*` 或 `+` (仅对于**无序**列表)。",
"config.toc.updateOnSave.description": "保存时自动更新目录。",
"showMe": "显示更新日志",
"dismiss": "忽略",
"noValidMarkdownFile": "未选中有效的 Markdown 文件",
"printing": "",
"to": "打印到",
"unableToReadFile": "无法读取文件",
"revertingToImagePaths": "已使用图像路径而不是 base64 编码",
"customStyle": "自定义样式",
"notFound": "未找到",
"cannotUseBuiltinSlugifyFunc": "无法使用 VSCode 内置的 slugify 函数,已使用 GitHub 的 slugify 函数替代。请尝试更新 VSCode 到最新版本,或将 `githubCompatibility` 设置为 `true`",
"1.3.0 msg": "介绍一个令人兴奋的功能!自动为有序列表重新编号",
"1.4.0 msg": "Markdown-All-in-One v1.4.0 带来很多新功能",
"1.5.0 msg": "好久不见!欢迎使用 Markdown-All-in-One v1.5.0",
"2.1.0 msg": "Markdown All in One v2.1.0! 直接粘贴链接,多光标支持,以及更多新功能",
"2.4.0 msg": "Markdown All in One v2.4.0! 新功能「触发列表」,KaTeX 宏支持",
"3.0.0 msg": "Markdown All in One v3.0.0! 新功能「添加章节序号」,以及更好的与其它语法扩展的兼容性"
"ui.exporting.messageCustomCssNotFound": "自定义样式 '{0}' 未找到。",
"ui.exporting.messageExportingInProgress": "将 '{0}' 打印到 {1} …",
"ui.exporting.messageRevertingToImagePaths": "已使用图像路径而不是 base64 编码。",
"ui.general.messageNoValidMarkdownFile": "未选中有效的 Markdown 文件。",
"ui.general.messageUnableToReadFile": "无法读取文件 '{0}'。",
"ui.welcome.buttonDismiss": "忽略",
"ui.welcome.buttonOpenLocal": "阅读"
}
26 changes: 26 additions & 0 deletions src/contract/VisualStudioCodeLocaleId.ts
@@ -0,0 +1,26 @@
"use strict";

/**
* Visual Studio Code Locale ID.
* @see <https://code.visualstudio.com/docs/getstarted/locales#_available-locales>
* @see <https://github.com/microsoft/vscode-loc>
*/
const enum VisualStudioCodeLocaleId {
Bulgarian = "bg",
ChineseSimplified = "zh-cn",
ChineseTraditional = "zh-tw",
Czech = "cs",
English = "en",
French = "fr",
German = "de",
Hungarian = "hu",
Italian = "it",
Japanese = "ja",
Korean = "ko",
PortugueseBrazil = "pt-br",
Russian = "ru",
Spanish = "es",
Turkish = "tr",
}

export default VisualStudioCodeLocaleId;
75 changes: 45 additions & 30 deletions src/extension.ts
@@ -1,20 +1,19 @@
'use strict';

import * as fs from 'fs';
import * as path from 'path';
import { ExtensionContext, languages, window, workspace } from 'vscode';
import { ExtensionContext, languages, Uri, window, workspace } from 'vscode';
import * as completion from './completion';
import * as formatting from './formatting';
import * as listEditing from './listEditing';
import localize from './localize';
import { config as configNls, localize } from './nls';
import resolveResource from "./nls/resolveResource";
import * as preview from './preview';
import * as print from './print';
import * as decorations from './syntaxDecorations';
import * as tableFormatter from './tableFormatter';
import * as toc from './toc';
import { getNewFeatureMsg, showChangelog } from './util';

export function activate(context: ExtensionContext) {
configNls({ extensionContext: context });
activateMdExt(context);

if (workspace.getConfiguration('markdown.extension.math').get<boolean>('enabled')) {
Expand Down Expand Up @@ -64,37 +63,53 @@ function activateMdExt(context: ExtensionContext) {
wordPattern: /(-?\d*\.\d\w*)|([^\!\@\#\%\^\&\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s\,\。\《\》\?\;\:\‘\“\’\”\(\)\【\】\、]+)/g
});

newVersionMessage(context.extensionPath);
showWelcome(context);
}

function newVersionMessage(extensionPath: string) {
let data: string, currentVersion: string;
/**
* Shows a welcome message on first time startup.
*/
async function showWelcome(context: ExtensionContext): Promise<void> {
const welcomeDirUri = Uri.joinPath(context.extensionUri, "welcome");

// The directory for an extension is recreated every time VS Code installs it.
// Thus, we only need to read and write an empty flag file there.
// If the file exists, then it's not the first time, and we don't need to do anything.
const flagFileUri = Uri.joinPath(welcomeDirUri, "WELCOMED");
try {
data = fs.readFileSync(`${extensionPath}${path.sep}package.json`).toString();
currentVersion = JSON.parse(data).version;
if (
fs.existsSync(`${extensionPath}${path.sep}VERSION`)
&& fs.readFileSync(`${extensionPath}${path.sep}VERSION`).toString() === currentVersion
) {
return;
}
fs.writeFileSync(`${extensionPath}${path.sep}VERSION`, currentVersion);
} catch (error) {
console.log(error);
await workspace.fs.stat(flagFileUri);
return;
} catch {
workspace.fs.writeFile(flagFileUri, new Uint8Array()).then(() => { }, () => { });
}
const featureMsg = getNewFeatureMsg(currentVersion);
if (featureMsg === undefined) return;
const message1 = localize("showMe");
const message2 = localize("dismiss");
window.showInformationMessage(featureMsg, message1, message2).then(option => {
switch (option) {
case message1:
showChangelog();
case message2:
break;

// The existence of welcome materials depends on build options we set during pre-publish.
// If any condition is not met, then we don't need to do anything.
try {
// Confirm the message is valid.
// `locale` should be a string. But here we keep it `any` to suppress type checking.
const locale: any = JSON.parse(process.env.VSCODE_NLS_CONFIG as string).locale;
const welcomeMessageFileUri = Uri.file(resolveResource(welcomeDirUri.fsPath, "", ".txt", [locale, "en"], "")![0]);
const msgWelcome = Buffer.from(await workspace.fs.readFile(welcomeMessageFileUri)).toString("utf8");
if (/^\s*$/.test(msgWelcome) || /\p{C}/u.test(msgWelcome)) {
return;
}
});

// Confirm the file exists.
const changelogFileUri = Uri.joinPath(context.extensionUri, "changes.md");
await workspace.fs.stat(changelogFileUri);

const btnDismiss = localize("ui.welcome.buttonDismiss");
const btnOpenLocal = localize("ui.welcome.buttonOpenLocal");

window.showInformationMessage(msgWelcome, btnOpenLocal, btnDismiss).then(selection => {
switch (selection) {
case btnOpenLocal:
workspace.openTextDocument(changelogFileUri).then(window.showTextDocument);
return;
}
});
} catch { }
}

export function deactivate() { }
99 changes: 0 additions & 99 deletions src/localize.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/nls/README.md
@@ -0,0 +1,3 @@
# National Language Support (NLS)

This module follows a pattern similar to [vscode-nls](https://github.com/microsoft/vscode-nls).

0 comments on commit 08c6f57

Please sign in to comment.