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

Include localized diagnostics #18702

Merged
merged 11 commits into from
Oct 3, 2017
Merged

Include localized diagnostics #18702

merged 11 commits into from
Oct 3, 2017

Conversation

mhegazy
Copy link
Contributor

@mhegazy mhegazy commented Sep 22, 2017

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
Member

@weswigham weswigham left a comment

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.

@@ -49,6 +49,8 @@
"@types/q": "latest",
"@types/run-sequence": "latest",
"@types/through2": "latest",
"@types/xml2js": "^0.4.0",
Copy link
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?

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

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

@weswigham weswigham Sep 22, 2017

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
Contributor Author

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
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.

Jakefile.js Outdated
@@ -641,7 +675,7 @@ task("build-fold-end", [], function () {

// 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
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
Contributor

@paulvanbrenk paulvanbrenk left a comment

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
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);
Copy link
Member

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>) {
Copy link
Member

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
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
Contributor Author

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
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 mhegazy merged commit a8b7f7d into master Oct 3, 2017
@mhegazy mhegazy deleted the includeLocalizedDiagnostics branch October 3, 2017 00:16
@mihailik
Copy link
Contributor

mihailik commented Oct 3, 2017

What would the error output look like?

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

@mhegazy
Copy link
Contributor Author

mhegazy commented Oct 3, 2017

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
Contributor Author

mhegazy commented Oct 3, 2017

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''ES
NEXT'。
 -m 種類, --module 種類                         モジュール コード生成を指定します: 'none''commonjs''amd''system''umd''es2015''ESNext'。
 --lib                                      コンパイルに含めるライブラリ ファイルを指定します:
                                              'es5' 'es6' 'es2015' 'es7' 'es2016' 'es2017' 'esnext' 'dom' 'dom.iterable' 'webworker' 'scripthost' 'es201
5.core' 'es2015.collection' 'es2015.generator' 'es2015.iterable' 'es2015.promise' 'es2015.proxy' 'es2015.reflect' 'es2015.symbol' 'es2015.symbol.wellkno
wn' '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 function types.
 --noImplicitThis                           暗黙的な 'any' 型を持つ 'this' 式でエラーが発生します。
 --alwaysStrict                             厳格モードで解析してソース ファイルごとに "use strict" を生成します。
 --noUnusedLocals                           使用されていないローカルに関するエラーを報告します。
 --noUnusedParameters                       使用されていないパラメーターに関するエラーを報告します。
 --noImplicitReturns                        関数の一部のコード パスが値を返さない場合にエラーを報告します。
 --noFallthroughCasesInSwitch               switch ステートメントに case のフォールスルーがある場合にエラーを報告します。
 --types                                    コンパイルに含む型宣言ファイル。
 @<ファイル>  

Sign up for free to 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