Skip to content

Commit

Permalink
Introduce resx for BuildValidator and MS.CA.Rebuild to allow localiza…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Youssef1313 committed May 16, 2021
1 parent 9db6a53 commit 4a63dda
Show file tree
Hide file tree
Showing 36 changed files with 1,189 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Compilers/Core/Rebuild/CompilationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public unsafe EmitResult Emit(
{
if (rebuildPdbStream is object)
{
throw new ArgumentException("PDB stream must be null because the compilation has an embedded PDB", nameof(rebuildPdbStream));
throw new ArgumentException(RebuildResources.PDB_stream_must_be_null_because_the_compilation_has_an_embedded_PDB, nameof(rebuildPdbStream));
}

debugInformationFormat = DebugInformationFormat.Embedded;
Expand All @@ -127,13 +127,13 @@ public unsafe EmitResult Emit(
{
if (rebuildPdbStream is null)
{
throw new ArgumentException("A non-null PDB stream must be provided because the compilation does not have an embedded PDB", nameof(rebuildPdbStream));
throw new ArgumentException(RebuildResources.A_non_null_PDB_stream_must_be_provided_because_the_compilation_does_not_have_an_embedded_PDB, nameof(rebuildPdbStream));
}

debugInformationFormat = DebugInformationFormat.PortablePdb;
var codeViewEntry = OptionsReader.PeReader.ReadDebugDirectory().Single(entry => entry.Type == DebugDirectoryEntryType.CodeView);
var codeView = OptionsReader.PeReader.ReadCodeViewDebugDirectoryData(codeViewEntry);
pdbFilePath = codeView.Path ?? throw new InvalidOperationException("Could not get PDB file path");
pdbFilePath = codeView.Path ?? throw new InvalidOperationException(RebuildResources.Could_not_get_PDB_file_path);
}

var rebuildData = new RebuildData(
Expand Down
8 changes: 4 additions & 4 deletions src/Compilers/Core/Rebuild/CompilationOptionsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public BlobReader GetMetadataCompilationOptionsBlobReader()
{
if (!TryGetMetadataCompilationOptionsBlobReader(out var reader))
{
throw new InvalidOperationException("Does not contain metadata compilation options");
throw new InvalidOperationException(RebuildResources.Does_not_contain_metadata_compilation_options);
}
return reader;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public string GetLanguageName()
var pdbCompilationOptions = GetMetadataCompilationOptions();
if (!pdbCompilationOptions.TryGetUniqueOption(CompilationOptionNames.Language, out var language))
{
throw new Exception("Invalid language name");
throw new Exception(RebuildResources.Invalid_language_name);
}

return language;
Expand Down Expand Up @@ -381,7 +381,7 @@ public IEnumerable<MetadataReferenceInfo> GetMetadataReferenceInfo()
// byte has data.
if ((embedInteropTypesAndKind & 0b11111100) != 0)
{
throw new InvalidDataException($"Unexpected value for EmbedInteropTypes/MetadataImageKind {embedInteropTypesAndKind}");
throw new InvalidDataException(string.Format(RebuildResources.Unexpected_value_for_EmbedInteropTypes_MetadataImageKind_0, embedInteropTypesAndKind));
}

var embedInteropTypes = (embedInteropTypesAndKind & 0b10) == 0b10;
Expand Down Expand Up @@ -465,7 +465,7 @@ where PdbReader.GetGuid(cdi.Kind) == infoGuid
{
if (value is null or { Length: 0 })
{
throw new InvalidDataException("Encountered null or empty key for compilation options pairs");
throw new InvalidDataException(RebuildResources.Encountered_null_or_empty_key_for_compilation_options_pairs);
}

key = value;
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/Core/Rebuild/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static void SkipNullTerminator(ref this BlobReader blobReader)
var b = blobReader.ReadByte();
if (b != '\0')
{
throw new InvalidDataException($"Encountered unexpected byte \"{b}\" when expecting a null terminator");
throw new InvalidDataException(string.Format(RebuildResources.Encountered_unexpected_byte_0_when_expecting_a_null_terminator, b));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/Core/Rebuild/MetadataCompilationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public string GetUniqueOption(string optionName)
var optionValues = _options.Where(pair => pair.optionName == optionName).ToArray();
if (optionValues.Length != 1)
{
throw new InvalidOperationException($"{optionName} exists {optionValues.Length} times in compilation options");
throw new InvalidOperationException(string.Format(RebuildResources._0_exists_1_times_in_compilation_options, optionName, optionValues.Length));
}

return optionValues[0].value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@
<ItemGroup>
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Rebuild.UnitTests" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="RebuildResources.resx" GenerateSource="true" />
</ItemGroup>
</Project>
150 changes: 150 additions & 0 deletions src/Compilers/Core/Rebuild/RebuildResources.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?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="0_exists_1_times_in_compilation_options" xml:space="preserve">
<value>'{0}' exists '{1}' times in compilation options.</value>
</data>
<data name="A_non_null_PDB_stream_must_be_provided_because_the_compilation_does_not_have_an_embedded_PDB" xml:space="preserve">
<value>A non-null PDB stream must be provided because the compilation does not have an embedded PDB.</value>
</data>
<data name="Cannot_create_compilation_options_0" xml:space="preserve">
<value>Cannot create compilation options: {0}</value>
</data>
<data name="Could_not_get_PDB_file_path" xml:space="preserve">
<value>Could not get PDB file path.</value>
</data>
<data name="Does_not_contain_metadata_compilation_options" xml:space="preserve">
<value>Does not contain metadata compilation options.</value>
</data>
<data name="Encountered_null_or_empty_key_for_compilation_options_pairs" xml:space="preserve">
<value>Encountered null or empty key for compilation options pairs.</value>
</data>
<data name="Encountered_unexpected_byte_0_when_expecting_a_null_terminator" xml:space="preserve">
<value>Encountered unexpected byte '{0}' when expecting a null terminator.</value>
</data>
<data name="Invalid_language_name" xml:space="preserve">
<value>Invalid language name.</value>
</data>
<data name="PDB_stream_must_be_null_because_the_compilation_has_an_embedded_PDB" xml:space="preserve">
<value>PDB stream must be null because the compilation has an embedded PDB.</value>
</data>
<data name="Unexpected_value_for_EmbedInteropTypes_MetadataImageKind_0" xml:space="preserve">
<value>Unexpected value for EmbedInteropTypes/MetadataImageKind '{0}'.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static VisualBasicCompilationOptions CreateVisualBasicCompilationOptions
var diagnostic = diagnostics?.FirstOrDefault(x => x.IsUnsuppressedError);
if (diagnostic is object)
{
throw new Exception($"Cannot create compilation options: {diagnostic}");
throw new Exception(string.Format(RebuildResources.Cannot_create_compilation_options_0, diagnostic));
}
}

Expand Down
57 changes: 57 additions & 0 deletions src/Compilers/Core/Rebuild/xlf/RebuildResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions src/Compilers/Core/Rebuild/xlf/RebuildResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4a63dda

Please sign in to comment.