陕西省建设工程造价管理协会网站,正规设计兼职网站有哪些,微商分销商城,百度做的网站迁移.net开发体系里#xff0c;大部分本地化的实现都是用资源文件实现(.resx)#xff0c;asp.net core中的多语Culture是指区域性的对象#xff0c;而UICulture 该对象表示资源管理器在运行时查找区域性特定资源时所用的当前用户接口区域性。asp.net core实现也是通过添注入本地… .net开发体系里大部分本地化的实现都是用资源文件实现(.resx)asp.net core中的多语Culture是指区域性的对象而UICulture 该对象表示资源管理器在运行时查找区域性特定资源时所用的当前用户接口区域性。asp.net core实现也是通过添注入本地化服务和添加中间件来实现的例如下using Microsoft.Extensions.Localization;var builder WebApplication.CreateBuilder(args);
//添加本地化中间件Resources
builder.Services.AddLocalization(options options.ResourcesPath Resources);var app builder.Build();
//应用三种本地化资源
var supportedCultures new[] { zh-CN, ja-JP, en-US };
var localizationOptions new RequestLocalizationOptions().SetDefaultCulture(supportedCultures[0]).AddSupportedCultures(supportedCultures).AddSupportedUICultures(supportedCultures);
localizationOptions.ApplyCurrentCultureToResponseHeaders true;
app.UseRequestLocalization(localizationOptions);
//通过向服务容器中获取StringLocalizer来获取具体本地化数据
app.MapGet(/demo, (IStringLocalizerSharedResource sharedLocalizer)
{return sharedLocalizer[ok].Value;
});app.Run();
//ShareResource类型不需要实现
public class SharedResource
{
}.resx文件类型.resx文档可视化界面.resx文件xml数据分描述部分和数据部分?xml version1.0 encodingutf-8?
root!-- Microsoft ResX Schema Version 2.0The 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 nameresmimetypetext/microsoft-resx/resheaderresheader nameversion2.0/resheaderresheader namereaderSystem.Resources.ResXResourceReader, System.Windows.Forms, .../resheaderresheader namewriterSystem.Resources.ResXResourceWriter, System.Windows.Forms, .../resheaderdata nameName1valuethis is my long string/valuecommentthis is a comment/comment/datadata nameColor1 typeSystem.Drawing.Color, System.DrawingBlue/datadata nameBitmap1 mimetypeapplication/x-microsoft.net.object.binary.base64value[base64 mime encoded serialized .NET Framework object]/value/datadata nameIcon1 typeSystem.Drawing.Icon, System.Drawing mimetypeapplication/x-microsoft.net.object.bytearray.base64value[base64 mime encoded string representing a byte array form of the .NET Framework object]/valuecommentThis is a comment/comment/dataThere 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 dont 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.base64value : 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.base64value : 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.base64value : The object must be serialized into a byte array : using a System.ComponentModel.TypeConverter: and then encoded with base64 encoding.--xsd:schema idroot xmlns xmlns:xsdhttp://www.w3.org/2001/XMLSchema xmlns:msdataurn:schemas-microsoft-com:xml-msdataxsd:import namespacehttp://www.w3.org/XML/1998/namespace /xsd:element nameroot msdata:IsDataSettruexsd:complexTypexsd:choice maxOccursunboundedxsd:element namemetadataxsd:complexTypexsd:sequencexsd:element namevalue typexsd:string minOccurs0 //xsd:sequencexsd:attribute namename userequired typexsd:string /xsd:attribute nametype typexsd:string /xsd:attribute namemimetype typexsd:string /xsd:attribute refxml:space //xsd:complexType/xsd:elementxsd:element nameassemblyxsd:complexTypexsd:attribute namealias typexsd:string /xsd:attribute namename typexsd:string //xsd:complexType/xsd:elementxsd:element namedataxsd:complexTypexsd:sequencexsd:element namevalue typexsd:string minOccurs0 msdata:Ordinal1 /xsd:element namecomment typexsd:string minOccurs0 msdata:Ordinal2 //xsd:sequencexsd:attribute namename typexsd:string userequired msdata:Ordinal1 /xsd:attribute nametype typexsd:string msdata:Ordinal3 /xsd:attribute namemimetype typexsd:string msdata:Ordinal4 /xsd:attribute refxml:space //xsd:complexType/xsd:elementxsd:element nameresheaderxsd:complexTypexsd:sequencexsd:element namevalue typexsd:string minOccurs0 msdata:Ordinal1 //xsd:sequencexsd:attribute namename typexsd:string userequired //xsd:complexType/xsd:element/xsd:choice/xsd:complexType/xsd:element/xsd:schemaresheader nameresmimetypevaluetext/microsoft-resx/value/resheaderresheader nameversionvalue2.0/value/resheaderresheader namereadervalueSystem.Resources.ResXResourceReader, System.Windows.Forms, Version4.0.0.0, Cultureneutral, PublicKeyTokenb77a5c561934e089/value/resheaderresheader namewritervalueSystem.Resources.ResXResourceWriter, System.Windows.Forms, Version4.0.0.0, Cultureneutral, PublicKeyTokenb77a5c561934e089/value/resheaderdata namecancel xml:spacepreservevalueCancel/value/datadata nameno xml:spacepreservevalueNo/value/datadata nameok xml:spacepreservevalueYes/value/data
/root