diff --git a/CSharpRepl.Services/Configuration.cs b/CSharpRepl.Services/Configuration.cs index 10a4c70..eb2fd85 100644 --- a/CSharpRepl.Services/Configuration.cs +++ b/CSharpRepl.Services/Configuration.cs @@ -170,7 +170,7 @@ public Configuration( submitPrompt, triggerOverloadList: new(new KeyPressPattern('('), new KeyPressPattern('['), new KeyPressPattern(','), new KeyPressPattern('<'))); - Culture = string.IsNullOrWhiteSpace(cultureName) ? CultureInfo.CurrentCulture : CultureInfo.GetCultureInfo(cultureName, true); + Culture = string.IsNullOrWhiteSpace(cultureName) ? CultureInfo.CurrentUICulture : CultureInfo.GetCultureInfo(cultureName, true); } public CultureInfo Culture { get; } diff --git a/CSharpRepl/Program.cs b/CSharpRepl/Program.cs index 6b867da..d89e36e 100644 --- a/CSharpRepl/Program.cs +++ b/CSharpRepl/Program.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.IO; using System.Text; using System.Threading.Tasks; @@ -35,6 +36,8 @@ internal static async Task Main(string[] args) if (!TryParseArguments(args, configFile, out var config)) return ExitCodes.ErrorParseArguments; + SetDefaultCulture(config); + if (config.OutputForEarlyExit.Text is not null) { console.WriteLine(config.OutputForEarlyExit); @@ -46,14 +49,14 @@ internal static async Task Main(string[] args) var roslyn = new RoslynServices(console, config, logger); // we're getting piped input, just evaluate the input and exit. - if(Console.IsInputRedirected) + if (Console.IsInputRedirected) { var evaluator = new PipedInputEvaluator(console, roslyn); return config.StreamPipedInput - ? await evaluator.EvaluateStreamingPipeInputAsync() - : await evaluator.EvaluateCollectedPipeInputAsync(); + ? await evaluator.EvaluateStreamingPipeInputAsync().ConfigureAwait(false) + : await evaluator.EvaluateCollectedPipeInputAsync().ConfigureAwait(false); } - else if(config.StreamPipedInput) + else if (config.StreamPipedInput) { console.WriteErrorLine("--streamPipedInput specified but no redirected input received. This configuration option should be used with redirected standard input."); return ExitCodes.ErrorParseArguments; @@ -107,18 +110,19 @@ private static string CreateApplicationStorageDirectory() return appStorage; } + private static void SetDefaultCulture(Configuration config) + { + CultureInfo.DefaultThreadCurrentUICulture = config.Culture; + // theoretically we shouldn't need to do the following, but in practice we need it in order to + // get compiler errors emitted by CSharpScript in the right language (see https://github.com/waf/CSharpRepl/issues/312) + CultureInfo.DefaultThreadCurrentCulture = config.Culture; + } + /// /// Initialize logging. It's off by default, unless the user passes the --trace flag. /// - private static ITraceLogger InitializeLogging(bool trace) - { - if (!trace) - { - return new NullLogger(); - } - - return TraceLogger.Create($"csharprepl-tracelog-{DateTime.UtcNow:yyyy-MM-dd}.txt"); - } + private static ITraceLogger InitializeLogging(bool trace) => + !trace ? new NullLogger() : TraceLogger.Create($"csharprepl-tracelog-{DateTime.UtcNow:yyyy-MM-dd}.txt"); private static (Prompt? prompt, int exitCode) InitializePrompt(IConsoleEx console, string appStorage, RoslynServices roslyn, Configuration config) {