Skip to content

Commit

Permalink
Merge pull request #33 from subframe7536/main
Browse files Browse the repository at this point in the history
add support for chinese lang
  • Loading branch information
yoavbls committed Apr 29, 2023
2 parents 90ab9b5 + 7c1762d commit e9b7d2d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/format/formatDiagnosticMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const formatDiagnosticMessage = (
message
// format declare module snippet
.replaceAll(
/'(declare module )'(.*)';'/g,
/['鈥淽(declare module )['鈥漖(.*)['鈥淽;['鈥漖/g,
(_: string, p1: string, p2: string) =>
formatTypeScriptBlock(_, `${p1} "${p2}"`)
)
Expand All @@ -44,7 +44,7 @@ export const formatDiagnosticMessage = (
)
// Format type pairs
.replaceAll(
/(types) '(.*?)' and '(.*?)'[\.]?/gi,
/(types) ['鈥淽(.*?)['鈥漖 and ['鈥淽(.*?)['鈥漖[\.]?/gi,
(_: string, p1: string, p2: string, p3: string) =>
`${formatTypeBlock(p1, p2, format)} and ${formatTypeBlock(
"",
Expand All @@ -54,7 +54,7 @@ export const formatDiagnosticMessage = (
)
// 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(
"",
Expand All @@ -63,40 +63,40 @@ export const formatDiagnosticMessage = (
)}`
)
.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|method's|subtype of constraint) '(.*?)'(?=[\s(.|,)])/gi,
/(type|type alias|interface|module|file|file name|method's|subtype of constraint) ['鈥淽(.*?)['鈥淽(?=[\s(.|,)])/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(
/'((?:(?!:\s*}).)*?)' (?!\s*:)/g,
/['鈥淽((?:(?!:\s*}).)*?)['鈥淽 (?!\s*:)/g,
(_: string, p1: string) => `${unStyledCodeBlock(p1)} `
);

0 comments on commit e9b7d2d

Please sign in to comment.