mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
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:
@@ -4,6 +4,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Utility
|
namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||||
{
|
{
|
||||||
@@ -18,6 +19,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
|||||||
public CommandOptions(string[] args)
|
public CommandOptions(string[] args)
|
||||||
{
|
{
|
||||||
ErrorMessage = string.Empty;
|
ErrorMessage = string.Empty;
|
||||||
|
Locale = string.Empty;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -26,18 +28,31 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
|||||||
string arg = args[i];
|
string arg = args[i];
|
||||||
if (arg.StartsWith("--") || arg.StartsWith("-"))
|
if (arg.StartsWith("--") || arg.StartsWith("-"))
|
||||||
{
|
{
|
||||||
|
// Extracting arguments and properties
|
||||||
arg = arg.Substring(1).ToLowerInvariant();
|
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":
|
case "-enable-logging":
|
||||||
EnableLogging = true;
|
EnableLogging = true;
|
||||||
break;
|
break;
|
||||||
|
case "-locale":
|
||||||
|
setLocale(argProperty);
|
||||||
|
break;
|
||||||
case "h":
|
case "h":
|
||||||
case "-help":
|
case "-help":
|
||||||
ShouldExit = true;
|
ShouldExit = true;
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
ErrorMessage += String.Format("Unknown argument \"{0}\"" + Environment.NewLine, arg);
|
ErrorMessage += String.Format("Unknown argument \"{0}\" with property \"{1}\"" + Environment.NewLine, argName, argProperty);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,6 +86,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ShouldExit { get; private set; }
|
public bool ShouldExit { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The locale our we should instantiate this service in
|
||||||
|
/// </summary>
|
||||||
|
public string Locale { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the usage string describing command-line arguments for the program
|
/// Get the usage string describing command-line arguments for the program
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -82,10 +102,32 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
|||||||
"Microsoft.SqlTools.ServiceLayer.exe " + Environment.NewLine +
|
"Microsoft.SqlTools.ServiceLayer.exe " + Environment.NewLine +
|
||||||
" Options:" + Environment.NewLine +
|
" Options:" + Environment.NewLine +
|
||||||
" [--enable-logging]" + Environment.NewLine +
|
" [--enable-logging]" + Environment.NewLine +
|
||||||
" [--help]" + Environment.NewLine,
|
" [--help]" + Environment.NewLine +
|
||||||
|
" [--locale **] (default: 'en')" + Environment.NewLine,
|
||||||
ErrorMessage);
|
ErrorMessage);
|
||||||
return str;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -421,6 +421,14 @@ namespace Microsoft.SqlTools.ServiceLayer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string TestLocalizationConstant
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Keys.GetString(Keys.TestLocalizationConstant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static string ConnectionServiceListDbErrorNotConnected(string uri)
|
public static string ConnectionServiceListDbErrorNotConnected(string uri)
|
||||||
{
|
{
|
||||||
return Keys.GetString(Keys.ConnectionServiceListDbErrorNotConnected, uri);
|
return Keys.GetString(Keys.ConnectionServiceListDbErrorNotConnected, uri);
|
||||||
@@ -672,6 +680,9 @@ namespace Microsoft.SqlTools.ServiceLayer
|
|||||||
public const string WorkspaceServiceBufferPositionOutOfOrder = "WorkspaceServiceBufferPositionOutOfOrder";
|
public const string WorkspaceServiceBufferPositionOutOfOrder = "WorkspaceServiceBufferPositionOutOfOrder";
|
||||||
|
|
||||||
|
|
||||||
|
public const string TestLocalizationConstant = "TestLocalizationConstant";
|
||||||
|
|
||||||
|
|
||||||
private Keys()
|
private Keys()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|||||||
123
src/Microsoft.SqlTools.ServiceLayer/sr.es.resx
Normal file
123
src/Microsoft.SqlTools.ServiceLayer/sr.es.resx
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="TestLocalizationConstant" xml:space="preserve">
|
||||||
|
<value>ES_LOCALIZATION</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
||||||
@@ -373,4 +373,8 @@
|
|||||||
<comment>.
|
<comment>.
|
||||||
Parameters: 0 - sLine (int), 1 - sCol (int), 2 - eLine (int), 3 - eCol (int) </comment>
|
Parameters: 0 - sLine (int), 1 - sCol (int), 2 - eLine (int), 3 - eCol (int) </comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TestLocalizationConstant" xml:space="preserve">
|
||||||
|
<value>EN_LOCALIZATION</value>
|
||||||
|
<comment></comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|||||||
@@ -175,4 +175,10 @@ WorkspaceServicePositionLineOutOfRange = Position is outside of file line range
|
|||||||
|
|
||||||
WorkspaceServicePositionColumnOutOfRange(int line) = Position is outside of column range for line {0}
|
WorkspaceServicePositionColumnOutOfRange(int line) = Position is outside of column range for line {0}
|
||||||
|
|
||||||
WorkspaceServiceBufferPositionOutOfOrder(int sLine, int sCol, int eLine, int eCol) = Start position ({0}, {1}) must come before or be equal to the end position ({2}, {3})
|
WorkspaceServiceBufferPositionOutOfOrder(int sLine, int sCol, int eLine, int eCol) = Start position ({0}, {1}) must come before or be equal to the end position ({2}, {3})
|
||||||
|
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
# Workspace Service
|
||||||
|
|
||||||
|
TestLocalizationConstant = EN_LOCALIZATION
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
// Copyright (c) Microsoft. All rights reserved.
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||||
@@ -47,5 +48,44 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
|||||||
var queryServiceQueryFailed = SR.QueryServiceQueryFailed("..");
|
var queryServiceQueryFailed = SR.QueryServiceQueryFailed("..");
|
||||||
var workspaceServiceBufferPositionOutOfOrder = SR.WorkspaceServiceBufferPositionOutOfOrder(1, 2, 3, 4);
|
var workspaceServiceBufferPositionOutOfOrder = SR.WorkspaceServiceBufferPositionOutOfOrder(1, 2, 3, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SrStringsTestWithEnLocalization()
|
||||||
|
{
|
||||||
|
string locale = "en";
|
||||||
|
var args = new string[] { "--locale " + locale };
|
||||||
|
CommandOptions options = new CommandOptions(args);
|
||||||
|
Assert.Equal(SR.Culture.Name, options.Locale);
|
||||||
|
Assert.Equal(options.Locale, locale);
|
||||||
|
|
||||||
|
var TestLocalizationConstant = SR.TestLocalizationConstant;
|
||||||
|
Assert.Equal(TestLocalizationConstant, "EN_LOCALIZATION");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SrStringsTestWithEsLocalization()
|
||||||
|
{
|
||||||
|
string locale = "es";
|
||||||
|
var args = new string[] { "--locale " + locale };
|
||||||
|
CommandOptions options = new CommandOptions(args);
|
||||||
|
Assert.Equal(SR.Culture.Name, options.Locale);
|
||||||
|
Assert.Equal(options.Locale, locale);
|
||||||
|
|
||||||
|
var TestLocalizationConstant = SR.TestLocalizationConstant;
|
||||||
|
Assert.Equal(TestLocalizationConstant, "ES_LOCALIZATION");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SrStringsTestWithNullLocalization()
|
||||||
|
{
|
||||||
|
SR.Culture = null;
|
||||||
|
var args = new string[] { "" };
|
||||||
|
CommandOptions options = new CommandOptions(args);
|
||||||
|
Assert.Null(SR.Culture);
|
||||||
|
Assert.Equal(options.Locale, "");
|
||||||
|
|
||||||
|
var TestLocalizationConstant = SR.TestLocalizationConstant;
|
||||||
|
Assert.Equal(TestLocalizationConstant, "EN_LOCALIZATION");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace Microsoft.SqlTools.Test.Utility
|
|||||||
|
|
||||||
Assert.True(options.EnableLogging);
|
Assert.True(options.EnableLogging);
|
||||||
Assert.False(options.ShouldExit);
|
Assert.False(options.ShouldExit);
|
||||||
|
Assert.Equal(options.Locale, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -33,6 +34,7 @@ namespace Microsoft.SqlTools.Test.Utility
|
|||||||
|
|
||||||
Assert.False(options.EnableLogging);
|
Assert.False(options.EnableLogging);
|
||||||
Assert.False(options.ShouldExit);
|
Assert.False(options.ShouldExit);
|
||||||
|
Assert.Equal(options.Locale, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -43,6 +45,7 @@ namespace Microsoft.SqlTools.Test.Utility
|
|||||||
Assert.NotNull(options);
|
Assert.NotNull(options);
|
||||||
|
|
||||||
Assert.True(options.ShouldExit);
|
Assert.True(options.ShouldExit);
|
||||||
|
Assert.Equal(options.Locale, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -53,6 +56,7 @@ namespace Microsoft.SqlTools.Test.Utility
|
|||||||
Assert.NotNull(options);
|
Assert.NotNull(options);
|
||||||
|
|
||||||
Assert.True(options.ShouldExit);
|
Assert.True(options.ShouldExit);
|
||||||
|
Assert.Equal(options.Locale, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -61,9 +65,49 @@ namespace Microsoft.SqlTools.Test.Utility
|
|||||||
var args = new string[] {};
|
var args = new string[] {};
|
||||||
CommandOptions options = new CommandOptions(args);
|
CommandOptions options = new CommandOptions(args);
|
||||||
Assert.NotNull(options);
|
Assert.NotNull(options);
|
||||||
|
|
||||||
Assert.False(options.EnableLogging);
|
Assert.False(options.EnableLogging);
|
||||||
Assert.False(options.ShouldExit);
|
Assert.False(options.ShouldExit);
|
||||||
|
Assert.Equal(options.Locale, string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("en")]
|
||||||
|
[InlineData("es")]
|
||||||
|
public void LocaleSetWhenProvided(string locale)
|
||||||
|
{
|
||||||
|
var args = new string[] {"--locale " + locale};
|
||||||
|
CommandOptions options = new CommandOptions(args);
|
||||||
|
|
||||||
|
// Asserting all options were properly set
|
||||||
|
Assert.NotNull(options);
|
||||||
|
Assert.False(options.ShouldExit);
|
||||||
|
Assert.Equal(options.Locale, locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ShouldExitSetWhenInvalidLocale()
|
||||||
|
{
|
||||||
|
string locale = "invalid";
|
||||||
|
var args = new string[] { "--locale " + locale };
|
||||||
|
CommandOptions options = new CommandOptions(args);
|
||||||
|
|
||||||
|
// Asserting all options were properly set
|
||||||
|
Assert.NotNull(options);
|
||||||
|
Assert.False(options.ShouldExit);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LocaleNotSetWhenNotProvided()
|
||||||
|
{
|
||||||
|
var args = new string[] {};
|
||||||
|
CommandOptions options = new CommandOptions(args);
|
||||||
|
|
||||||
|
// Asserting all options were properly set
|
||||||
|
Assert.NotNull(options);
|
||||||
|
Assert.False(options.EnableLogging);
|
||||||
|
Assert.False(options.ShouldExit);
|
||||||
|
Assert.Equal(options.Locale, string.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user