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

add support for chinese lang #33

Merged
merged 2 commits into from
Apr 29, 2023
Merged
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
22 changes: 11 additions & 11 deletions src/format/formatDiagnosticMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const formatDiagnosticMessage = (message: string, format: (type: string)
message
// format declare module snippet
.replaceAll(
/'(declare module )'(.*)';'/g,
/['“](declare module )['”](.*)['“];['”]/g,
Copy link
Owner

Choose a reason for hiding this comment

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

It should be better to replace all the characters by ' at the beginning in one replace instead of adding it to all the others.
WDYT?

Copy link
Contributor Author

@subframe7536 subframe7536 Apr 22, 2023

Choose a reason for hiding this comment

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

I thought the same way, but I can't guarantee that all “” inside error messages are just used as the replacement of ''

Copy link
Owner

Choose a reason for hiding this comment

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

I didn't see inside a type before, but I didn't use the Chinese language pack so we'll go with the safe option for now 🙂
Thank you!

(_: string, p1: string, p2: string) =>
formatTypeScriptBlock(_, `${p1} "${p2}"`)
)
Expand All @@ -36,48 +36,48 @@ export const formatDiagnosticMessage = (message: string, format: (type: string)
)
// Format type pairs
.replaceAll(
/(types) '(.*?)' and '(.*?)'[\.]?/gi,
/(types) ['“](.*?)['”] and ['“](.*?)['”][\.]?/gi,
(_: string, p1: string, p2: string, p3: string) =>
`${formatTypeBlock(p1, p2, format)} and ${formatTypeBlock("", p3, format)}`
)
// Format type annotation options
.replaceAll(
/type annotation must be '(.*?)' or '(.*?)'[\.]?/gi,
/type annotation must be ['“](.*?)['”] or ['“](.*?)['”][\.]?/gi,
(_: string, p1: string, p2: string, p3: string) =>
`${formatTypeBlock(p1, p2, format)} or ${formatTypeBlock("", p3, format)}`
)
.replaceAll(
/(Overload \d of \d), '(.*?)', /gi,
/(Overload \d of \d), ['“](.*?)['”], /gi,
(_, p1: string, p2: string) => `${p1}${formatTypeBlock("", p2, format)}`
)
// format simple strings
.replaceAll(/^'"[^"]*"'$/g, formatTypeScriptBlock)
.replaceAll(/^['“]"[^"]*"['”]$/g, formatTypeScriptBlock)
// Format types
.replaceAll(
/(type|type alias|interface|module|file|file name) '(.*?)'[\.]?/gi,
/(type|type alias|interface|module|file|file name) ['“](.*?)['”][\.]?/gi,
(_, p1: string, p2: string) => formatTypeOrModuleBlock(_, p1, p2, format)
)
// Format reversed types
.replaceAll(
/(.*)'([^>]*)' (type|interface|return type|file|module)/gi,
/(.*)['“]([^>]*)['”] (type|interface|return type|file|module)/gi,
(_: string, p1: string, p2: string, p3: string) =>
`${p1}${formatTypeOrModuleBlock(_, "", p2, format)} ${p3}`
)
// Format simple types that didn't captured before
.replaceAll(
/'((void|null|undefined|any|boolean|string|number|bigint|symbol)(\[\])?)'/g,
/['“]((void|null|undefined|any|boolean|string|number|bigint|symbol)(\[\])?)['”]/g,
formatSimpleTypeBlock
)
// Format some typescript key words
.replaceAll(
/'(import|export|require|in|continue|break|let|false|true|const|new|throw|await|for await|[0-9]+)( ?.*?)'/g,
/['“](import|export|require|in|continue|break|let|false|true|const|new|throw|await|for await|[0-9]+)( ?.*?)['”]/g,
(_: string, p1: string, p2: string) =>
formatTypeScriptBlock(_, `${p1}${p2}`)
)
// Format return values
.replaceAll(
/(return|operator) '(.*?)'/gi,
/(return|operator) ['“](.*?)['”]/gi,
(_, p1: string, p2: string) => `${p1} ${formatTypeScriptBlock("", p2)}`
)
// Format regular code blocks
.replaceAll(/'(.*?)'/g, (_: string, p1: string) => unstyledCodeBlock(p1));
.replaceAll(/['“](.*?)['”]/g, (_: string, p1: string) => unstyledCodeBlock(p1));