Internationalisation with asp.net, c# and VSCode - c#

I would like to create an internationalization file in my asp.net project using VS Code. I just found how to do it using a common VS version, just creating a .resx file, and using a specific interface to insert the variables and the value.
How can I create an internationalization file using Visual Studio Code?

Visual Studio Code is not an IDE. It's a Code Editor. So you can't add new item types like you get that menu with the full Visual Studio. Instead, you can add text files, give them the proper extension, and fill them out accordingly.
A resource file is .resx, and here's a starter one made with Visual Studio Community that you can use:
<?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="MyString" xml:space="preserve">
<value>My Value</value>
<comment>My Comment</comment>
</data>
</root>

Resx files are only going to partially function in VS Code.
Typically, a resx file produces two artifacts: an embedded resource in your assembly, and a code file containing APIs to access your resources by name.
The embedded resource is created from an MSBuild task, so it will be handled as long as you are building with MSBuild, which is pretty standard for any .NET project.
However, the code file that gets generated is created by a "Custom Tool" in Visual Studio, so you won't get that for free if you use VSCode. This generated code file can be written by hand, but it isn't much fun keeping it in sync with your .resx.
As an alternative to .resx, I've been working on creating a .resj file format. This functions entirely in MSBuild, and so should work just as well from VSCode as it does from Visual Studio. The project is open sourced here. I've packaged it up as a nuget package "Elemental.JsonResource" (currently only pre-release). If you add that package to your project you should be able to use .resj files. Currently, it only supports string resources, but I hope to add support for other resource types in the future. It doesn't add a run-time dependency to your project, it only operates at build time.

Related

C# Ressources (Resx) Namespace should not match Project Folder Structure - Jetbrains Rider Ressource Editor

I have a Resx-File in a C#-Project-File (Project name: Core.Common) with many folders and I want the Ressources always to be on top in the folder structure so that I can quickly switch to them. I need them regularly.
So I prefixed the Foldername with an Underscore(_) so that it is _Ressourcen.
But I do not want the namespace to reflect this since it would not be CLS-Compliant.
Instead I want it to be esRessourcen.
But now if i change it in the Jetbrains Rider-Resx-Editor the part with the ResourceManager in the designer always gets the Namespace from the folder again (Core.Common._Ressourcen).
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Core.Common._Ressourcen.DayOfWeek", typeof(DayOfWeek).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
Is there a way to fix this?
Here is the complete DayOfWeek.resx
<?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="Sonntag" xml:space="preserve">
<value>Sonntag</value>
</data>
</root>
And the complete DayOfWeek.Designer.cs
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Core.Common.esRessourcen {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class DayOfWeek {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal DayOfWeek() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Core.Common._Ressourcen.DayOfWeek", typeof(DayOfWeek).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Sonntag.
/// </summary>
internal static string Sonntag {
get {
return ResourceManager.GetString("Sonntag", resourceCulture);
}
}
}
}
I tried the following in the .csproj-File but this did not solve the problem:
<EmbeddedResource Include="_Ressourcen\DayOfWeek.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>DayOfWeek.Designer.cs</LastGenOutput>
<CustomToolNamespace>Core.Common.esRessourcen</CustomToolNamespace>
</EmbeddedResource>

How can I read XSD data in my c# and print to console? And there is import tag with Schemalocation so how can I import that in c#?

I have one XSD file as below:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:gml="http://www.opengis.net/gml" xmlns:njdot="SomeURL" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="SomeURL">
<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="SomeURL/feature.xsd"/>
<xsd:complexType name="StudentType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractfeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="StudentId" nillable="false" type="xsd:decimal"/>
<xsd:element maxOccurs="1" minOccurs="1" name="class_ID" nillable="false" type="xsd:decimal"/>
<xsd:element maxOccurs="1" minOccurs="1" name="Name" nillable="false" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="Student" substitutionGroup="gml:_Feature" type="njdot:StudentType"/>
</xsd:schema>
My requirement is : Read this XSD data into c# on flying and Print them to console.
Currently while compiling XSD, I am getting following error:
Undefined complexType 'http://www.opengis.net/gml:AbstractFeatureType' is used as a base for complex type extension.
Error: Reference to undeclared substitution group affiliation.
I think I am not importing the external schema which is given with
Can anyone suggest what can be the solution or how can I achieve my desired output?
Thanks in advance.

WSDL The data type 'xxxx: AuthorizationFilter' does not exist

I am trying to generate classes from WSDL using visual studio Developer command prompt for vs2017.
I am using the command :
wsdl.exe xxx.wsdl file.xsd file2.xsd .....
the WSDL is created in Java and I trying to connect to WSDL from c# project but I get always the same problem:
Error: The xxxServicePortBinding binding of namespace 'urn:
xxx3Services-1-1-0' cannot be imported.
- The login process cannot be imported.
- The data type 'urn: xxxxServiceTypes-1-1-0: AuthorizationFilter' does not exist.
I went to xsd "xxxxServiceTypes-1-1-0" and the code of AuthorizationFilter is like:
<xsd:complexType name="DeclareEndpointRequest_Type">
<xsd:annotation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="VUNr" type="omds:VUNr" minOccurs="0"/>
<xsd:element name="BasisUrlEndpoint">
<xsd:annotation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="1000"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element ref="ArtAuthentifizierung"/>
<xsd:element name="Credentials" type="Credentials_Type">
<xsd:annotation>
</xsd:annotation>
</xsd:element>
<xsd:element name="AuthorizationFilter" type="cst:AuthorizationFilter" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
Is there is any tipp that could help me to generat classes from thee WSDL.
The answer was that I should insert the reference of the source of AuthorizationFilter in my project in my case it was the system.web.mvc

xsd to c# without included xsd

To generate classes from xsd file is it necessary need included/imported xsd? Is possible to generate it without included/imported xsd? Because I want write own xsd to C# classes generator.
<?xml version="1.0"?>
<xsd:schema xmlns="" xmlns:Extended="" xmlns:xsd="" targetNamespace="">
<xsd:include schemaLocation="file2.xsd"/>
<xsd:import namespace="" schemaLocation="file2.xsd"/>
<xsd:complexType name="ActualEndTimeType">
<xsd:simpleContent>
<xsd:restriction base="DateTimeType"/>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="ActualFinishTimeType">
<xsd:simpleContent>
<xsd:restriction base="DateTimeType"/>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="ActualStartTimeType">
<xsd:simpleContent>
<xsd:restriction base="DateTimeType"/>
</xsd:simpleContent>
</xsd:complexType>
<-- etc... -->
</xsd:schema>

Turn off CXF Aegis Inheritance support / Use Inheritance with DataContractSerializer?

I use Apache CXF with Aegis data binding to provide a Java web service to a C# client. This works in principle very well. On the C# side, I would like to use the more limited DataContractSerializer, because it allows for collections instead of arrays. I understand using the DataContractSerializer limits the complexity of the Aegis-generated WSDL. Now I have a Java type that uses inheritance. Aegis is able to generate a WSDL that contains both the base and the derived type, but the DataContractSerializer does not seem to be able to understand this WSDL. SvcUtil falls back to the XmlSerializer, and my collections get ugly arrays.
I can imagine thee theoretical possibilities to deal with this issue:
Turn off Inheritance support with Aegis. This should cause the WSDL to contain only the derived types, containing each all of the base type properties.
Somehow make DataContractSerializer understand WSDL inheritance
Somehow make XmlSerializer use collections instead of arrays
I think the last two options are not possible, so I am stuck with the first one. How can I turn off Aegis inheritance?
Example WSDL fragment:
<xsd:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://tables.basic.meona.de">
<xsd:complexType abstract="true" name="BaseTreeNode">
<xsd:sequence>
<xsd:element minOccurs="0" name="active" type="xsd:boolean"/>
<xsd:element minOccurs="0" name="category" type="xsd:boolean"/>
<xsd:element minOccurs="0" name="name" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="sequenceNumber" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<xsd:complexType name="EmergencyDiagnosis">
<xsd:complexContent>
<xsd:extension base="ns0:BaseTreeNode">
<xsd:sequence>
<xsd:element minOccurs="0" name="externalCode" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="favoriteDiagnosis" type="xsd:boolean"/>
<xsd:element minOccurs="0" name="identifier" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
It seems former versions of Aegis did not generate the extension, so I am hoping it can be switched off: https://issues.apache.org/jira/browse/CXF-5176
After reading the Aegis source code, I helped myself with the following hack:
public class AegisNonExtensionBeanType extends BeanType {
#Override
public BeanTypeInfo getTypeInfo() {
BeanTypeInfo bti = super.getTypeInfo();
bti.setExtension(false);
bti.setExtensibleAttributes(false);
bti.setExtensibleElements(false);
return bti;
}
#Override
public AegisType getSuperType() {
return null;
}
}
If I register this AegisType for my inherited beans, it works.
Mustn't there be a better way?

Categories

Resources