yoavbls / pretty-ts-errors

πŸ”΅ Make TypeScript errors prettier and human-readable in VSCode πŸŽ€
https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors
MIT License
13.29k stars 89 forks source link

Support more languages and locales #27

Open JUSTIVE opened 1 year ago

JUSTIVE commented 1 year ago
image

Syntax highlighting should be fixed in other languages(Korean, in this case). If you're unfamiliar with other languages that reproduce these kinds of issues, I'll try to contribute PR with this issue.

yoavbls commented 1 year ago

Thank you for opening the issue! I wasn't even aware that tsc have a locale flag. I saw that VSCode provides it by default if the locale is supported, the languages generated by this: https://github.com/microsoft/TypeScript/blob/main/scripts/generateLocalizedDiagnosticMessages.mjs

So I think the easiest option is to maintain a mapping between language words the English words we use at the regexes here https://github.com/yoavbls/pretty-ts-errors/blob/main/src/format/formatDiagnosticMessage.ts

JUSTIVE commented 1 year ago

I'll start by making types of regexes. for example,

export type FormatDiagnosticMessageTarget = 
  | "DeclareModuleSnippet"
  | "MissingPropsError"
  | "TypePairs"
  | "TypeAnnotationOptions"
  | "Overloaded"
  | "SimpleStrings"
  | "Types"
  | "ReversedTypes"
  | "SimpleTypesRest"
  | "TypescriptKeywords"
  | "ReturnValues"
  | "RegularCodeBlocks";

(I have no clue what kind of those regexes are, but I guessed from your very detailly described comments)

and making some constants with type at /src/format/i18n

type LocaleFormatDiagnosticMessageTarget = Record<FormatDiagnosticMessageTarget, RegExp>

// en.ts
const en:LocaleFormatDiagnosticMessageTarget = {
  DeclareModuleSnippet: /'(declare module )'(.*)';'/g,
  ...
}

Which will be constructed like Record<SupportedLocale, LocaleFormatDiagnosticMessageTarget>.

What do you think of it?

xlboy commented 1 year ago

This makes me see the hope of other languages

JUSTIVE commented 1 year ago

btw, it would be great to have a detailed contribution document. I'm trying to find out how to test & watch in the development environment.

and also example codes which generates each error messages

cat-walk commented 1 year ago

Has the same request, hope to support Chinese in the future version~

JUSTIVE commented 1 year ago

@yoavbls I'm keep struggling on executing this repository in development environment. I'm novice to vscode extension, so could you help me how to do it?

yoavbls commented 1 year ago

@JUSTIVE Sorry for my late response and thank you for all the effort and the contribution even though there is no contribution guide. I'm working on migration to a monorepo so things will change. After that, I will add a simple contribution guide with a debugging explanation. Until then, we can talk about the multi-language implementation and how to debug and test things on messaging, Are you available on Discord?

JUSTIVE commented 1 year ago

yes, I'm available on discord, my handle is λΉ„μŠ€ν‚·#0869.

CzarOfScripts commented 1 year ago

@yoavbls, Any progress? Thanks for your input!

yoavbls commented 11 months ago

@CzarOfScripts Sorry, no progress happened. I'm still looking for a feasible method to implement it. Maybe as a TypeScript server LSP plugin. JetBrains are doing something with the LSP and I wish I knew what