SeedV / SeedLang

An embeddable and visualizable scripting engine for .Net and Unity.
https://seedv.github.io/SeedLang/
Apache License 2.0
9 stars 1 forks source link

Support localized messages #231

Closed wixette closed 2 years ago

wixette commented 2 years ago

With this PR, SeedLang.Shell outputs error messages in the following way (only SyntaxErrorMissingToken2 is localized in this PR):

>>> def a()
---------- Source ----------
1     def a()

---------- Compile Error ----------
1     def a()
: 20220809205400297 Fatal (SeedLang.X) <> [Ln 1, Col 7 - Ln 1, Col 7] 29: Missing token. Found token: '\n'. Expected token: ':'
: 20220809205400299 Fatal (SeedLang.X) <> [Ln 2, Col 0 - Ln 2, Col -1] 28: SyntaxErrorInputMismatch '<EOF>' INDENT

After setting the current locale in SeedLang.Shell with

CultureInfo.CurrentCulture = new CultureInfo("zh-CN");

SeedLang.Shell outputs Chinese info like below:

>>> def a()
---------- Source ----------
1     def a()

---------- Compile Error ----------
1     def a()
: 20220809210408162 Fatal (SeedLang.X) <> [Ln 1, Col 7 - Ln 1, Col 7] 29: 缺少 token. 遇到的 token: '\n'. 期望的 token: ':'
: 20220809210408164 Fatal (SeedLang.X) <> [Ln 2, Col 0 - Ln 2, Col -1] 28: SyntaxErrorInputMismatch '<EOF>' INDENT