Task: localization for the sqltoolsservice (#226)

* locale set through CLI and tests updated

* adding cli locale support

* adding tests and test constants

* cleaning up new tests

* fixing test which only fails remotely

* adding support for MacOS/Linux

* triggering new build due to appveyor timeout

* updating usage printout
This commit is contained in:
Raymond Martin
2017-02-09 13:25:12 -08:00
committed by GitHub
parent b10d6bdfdc
commit 74b8d359ec
7 changed files with 275 additions and 5 deletions

View File

@@ -4,6 +4,7 @@
//
using System;
using System.Globalization;
namespace Microsoft.SqlTools.ServiceLayer.Utility
{
@@ -18,6 +19,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
public CommandOptions(string[] args)
{
ErrorMessage = string.Empty;
Locale = string.Empty;
try
{
@@ -26,18 +28,31 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
string arg = args[i];
if (arg.StartsWith("--") || arg.StartsWith("-"))
{
// Extracting arguments and properties
arg = arg.Substring(1).ToLowerInvariant();
switch (arg)
string argName = arg;
string argProperty = "";
int splitIndex = arg.IndexOf(' ');
if (splitIndex > 0)
{
argName = arg.Substring(0, splitIndex);
argProperty = arg.Substring(splitIndex + 1);
}
switch (argName)
{
case "-enable-logging":
EnableLogging = true;
break;
case "-locale":
setLocale(argProperty);
break;
case "h":
case "-help":
ShouldExit = true;
return;
default:
ErrorMessage += String.Format("Unknown argument \"{0}\"" + Environment.NewLine, arg);
ErrorMessage += String.Format("Unknown argument \"{0}\" with property \"{1}\"" + Environment.NewLine, argName, argProperty);
break;
}
}
@@ -71,6 +86,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
/// </summary>
public bool ShouldExit { get; private set; }
/// <summary>
/// The locale our we should instantiate this service in
/// </summary>
public string Locale { get; private set; }
/// <summary>
/// Get the usage string describing command-line arguments for the program
/// </summary>
@@ -82,10 +102,32 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
"Microsoft.SqlTools.ServiceLayer.exe " + Environment.NewLine +
" Options:" + Environment.NewLine +
" [--enable-logging]" + Environment.NewLine +
" [--help]" + Environment.NewLine,
" [--help]" + Environment.NewLine +
" [--locale **] (default: 'en')" + Environment.NewLine,
ErrorMessage);
return str;
}
}
private void setLocale(string locale){
try
{
// Creating cultureInfo from our given locale
CultureInfo language = new CultureInfo(locale);
Locale = locale;
// Setting our language globally
CultureInfo.CurrentCulture = language;
CultureInfo.CurrentUICulture = language;
// Setting our internal SR culture to our global culture
SR.Culture = CultureInfo.CurrentCulture;
}
catch(Exception ex)
{
// Warn user of invalid locale, and fall back to english
Console.WriteLine(ex);
}
}
}
}