Skip to content

Include localized diagnostics - #18702

Merged
Mohamed Hegazy (mhegazy) merged 11 commits into
masterfrom
includeLocalizedDiagnostics
Oct 3, 2017
Merged

Include localized diagnostics#18702
Mohamed Hegazy (mhegazy) merged 11 commits into
masterfrom
includeLocalizedDiagnostics

Conversation

@mhegazy

Copy link
Copy Markdown
Contributor

Include localized error messages with the ts package. Localized error messages will be under lib\<locale id>\diagnosticMessages.generated.json. running tsc --locale rus for instance should load the diagnostic messages file from lib\rus\diagnosticMessages.generated.json.

for background, the diagnosticMessages.generated.json is a just a map from diagnostic message id => diagnostic message text. the compiler comes in with one already for English. When the --locale is passed, the compiler tries to load the .json map from a folder with matching locale name.

Messages are localized by the MS localization team. The communication with the loc team is all done in a specific XML formats, the .lcg files are used to specify the messages to be localized, the .lcl files have the result of the localization. The loc team will be monitoring the repo and should be periodically inserting new .lcl files with localized messages as we add/change messages.

The change adds:

  • Existing .lcl files we have used in previous version of the VS with localization for existing messages.
  • A script that converts src\compiler\diagnosticMessages.generated.json into the .lcg format and convert the existing .lcl files back into .json format.
  • Build files (jake/gulp) updates to allow for building the new localized messages.

Fixes#13703

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably also add generateLocalizedDiagnosticMessages.ts to the list of linted files in the Gulpfile and Jakefile, before we forget about it and never lint it.

Comment threadpackage.json
"@types/q": "latest",
"@types/run-sequence": "latest",
"@types/through2": "latest",
"@types/xml2js": "^0.4.0",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be latest, unless we have a strong reason to fix the version, yes?

Comment threadGulpfile.ts
const generateLocalizedDiagnosticMessagesJs = path.join(scriptsDirectory, "generateLocalizedDiagnosticMessages.js");
const generateLocalizedDiagnosticMessagesTs = path.join(scriptsDirectory, "generateLocalizedDiagnosticMessages.ts");

gulp.task(generateLocalizedDiagnosticMessagesJs, /*help*/ false, [], () => {

@weswighamWesley Wigham (weswigham)Sep 22, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than building the script in the gulpfile, can we just import the typescript directly, and call a function it exports (instead of shelling out)? We could do this with our other scripts in the Gulpfile to cut away some cruft, too.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we doing this anywhere else in gulpFile? i tried to stay close to the Jake file really. i am not a gulp user :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were doing it for the old parallel runner, though I've removed it since it's in the harness now. It's no big deal; could just be a little cleaner-feeling, since then there'd be no (visible) compilation step for the script. Doesn't matter much, since we need to keep the compilation step in the Jakefile anyway.

Comment threadJakefile.js Outdated
// Local target to build the compiler and services
desc("Builds the full compiler and services");
task("local", ["build-fold-start", "generate-diagnostics", "lib", tscFile, servicesFile, nodeDefinitionsFile, serverFile, buildProtocolDts, builtGeneratedDiagnosticMessagesJSON, "lssl", "build-fold-end"]);
task("local", ["build-fold-start", "generate-diagnostics", "lib", tscFile, servicesFile, nodeDefinitionsFile, serverFile, buildProtocolDts, builtGeneratedDiagnosticMessagesJSON, "lssl", "build-fold-end", "localize"]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"localize" should come before "build-fold-end", probably.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed we should consider building the NPM packages on the build server vs. this another machine. This way we can include signing in the future.

}
}

function xmlObjectToString(o: any) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here what we expect the incoming XML to look like


// generate other langs
fs.readdir(inputPath, (err, files) => {
handelError(err);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle :)

});
}

function objectToList(o: Record<string, string>) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're assuming an ES2015 runtime, you can use Object.entries instead, but this is probably fine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already use const in some of our build scripts, I believe, and haven't received any complaints. We only build on back to Node 4, so it seems reasonable.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.entries is ES2017. not sure if was on node v4 or not..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to http://node.green/, node 7.5 was the first with Object.entries... so probably not yet. However map.entries has been available since node 4. 🐱

@mhegazy
Mohamed Hegazy (mhegazy) deleted the includeLocalizedDiagnostics branch October 3, 2017 00:16
@mihailik

Copy link
Copy Markdown
Contributor

What would the error output look like?

error TS2318: BlaBlaInForeignLanguage
^^^^^ that's English, right?

@mhegazy

Copy link
Copy Markdown
ContributorAuthor
c:\ts>tsc --v
Version 2.6.0-dev.20171003
c:\ts>tsc --locale rus --pretty c:\test\a.ts
../test/a.ts(1,5): error TS2322: Тип ""string"" не может быть назначен для типа "number".
1 var x: number = "string";~

@mhegazy

Copy link
Copy Markdown
ContributorAuthor

And help in JPN would look like:

PS C:\ts> tsc --v
Version 2.6.0-dev.20171003
PS C:\ts> tsc --locale jpn
バージョン 2.6.0-dev.20171003
構文: tsc [オプション] [ファイル ...]
例: tsc hello.ts
tsc --outFile file.js file.ts
tsc @args.txt
オプション:
-h, --help このメッセージを表示します。
--all コンパイラ オプションをすべて表示します。
-v, --version コンパイラのバージョンを表示します。
--init TypeScript プロジェクトを初期化して、tsconfig.json ファイルを作成します。
-p ファイルまたはディレクトリ, --project ファイルまたはディレクトリ 構成ファイルか、'tsconfig.json' を含むフォルダーにパスが指定されたプロジェクトをコ
ンパイルします。
--pretty 色とコンテキストを使用してエラーとメッセージにスタイルを適用します (試験的)。
-w, --watch 入力ファイルを監視します。
-t バージョン, --target バージョン ECMAScript のターゲット バージョンを指定します: 'ES3' (既定)、'ES5''ES2015''ES2016''ES2017''ESNEXT'。
-m 種類, --module 種類 モジュール コード生成を指定します: 'none''commonjs''amd''system''umd''es2015''ESNext'。
--lib コンパイルに含めるライブラリ ファイルを指定します:
'es5''es6''es2015''es7''es2016''es2017''esnext''dom''dom.iterable''webworker''scripthost''es2015.core''es2015.collection''es2015.generator''es2015.iterable''es2015.promise''es2015.proxy''es2015.reflect''es2015.symbol''es2015.symbol.wellknown''es2016.array.include''es2017.object''es2017.sharedmemory''es2017.string''es2017.intl''esnext.asynciterable'
--allowJs javascript ファイルのコンパイルを許可します。
--jsx 種類 JSX コード生成を指定します: 'preserve''react-native''react'。
-d, --declaration 対応する '.d.ts' ファイルを生成します。
--sourceMap 対応する '.map' ファイルを生成します。
--outFile ファイル 出力を連結して 1 つのファイルを生成します。
--outDir ディレクトリ ディレクトリへ出力構造をリダイレクトします。
--removeComments コメントを出力しないでください。
--noEmit 出力しないでください。
--strict strict 型チェックのオプションをすべて有効にします。
--noImplicitAny 暗黙的な 'any' 型を含む式と宣言に関するエラーを発生させます。
--strictNullChecks 厳格な null チェックを有効にします。
--strictFunctionTypes Enable strict checking of functiontypes.
--noImplicitThis 暗黙的な 'any' 型を持つ 'this' 式でエラーが発生します。
--alwaysStrict 厳格モードで解析してソース ファイルごとに "use strict" を生成します。
--noUnusedLocals 使用されていないローカルに関するエラーを報告します。
--noUnusedParameters 使用されていないパラメーターに関するエラーを報告します。
--noImplicitReturns 関数の一部のコード パスが値を返さない場合にエラーを報告します。
--noFallthroughCasesInSwitch switch ステートメントに case のフォールスルーがある場合にエラーを報告します。
--types コンパイルに含む型宣言ファイル。
@<ファイル>

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@mhegazy@mihailik@DanielRosenwasser@weswigham@paulvanbrenk@msftclas@msftgits