5.22Setting the Client's Preferred Language and Region
Globalization is the development trend for internet application products; therefore, products targeting a global audience should support internationalization. When sending HTTP requests, you can specify the client's preferred natural language and region by adding the AcceptLanguageAttribute attribute.
HTTP Declarative Requests set the client's preferred language and region through the AcceptLanguageAttribute attribute. The corresponding HTTP declarative extractor is implemented as the AcceptLanguageDeclarativeExtractor type, which is responsible for parsing the AcceptLanguageAttribute attribute and building the client's preferred language and region configuration required for an HttpRequestBuilder instance.
// Applied at the interface level, affects all methods[AcceptLanguage("en-US")]public interface IHttpService : IHttpDeclarative{ // Applied at the method level [AcceptLanguage("zh-CN,en;q=0.5")] [Get("https://furion.net/")] Task<string> GetStringAsync(); [AcceptLanguage("fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5")] [Get("https://furion.net/")] Task<string> GetStringAsync();}AcceptLanguageAttribute contains the following constructors and properties:
-
Constructors:
new(language): Applies to methods or interfaces and configures the client's preferred language and region.
-
Properties:
Language: The client's preferred language and region (typestring).