• net core 3.1 Global


    NET CORE 3.1多语言

    控制器多语言
    ConfigureServices 1

    services.AddLocalization(o =>
    {
    o.ResourcesPath = "Resources";
    });
    services.AddMvc();

    Configure 2
    IList<CultureInfo> supportedCultures = new List<CultureInfo>
    {
    new CultureInfo("en-US"),
    new CultureInfo("zh-CN"),
    };
    app.UseRequestLocalization(new RequestLocalizationOptions
    {
    DefaultRequestCulture = new RequestCulture("en-US"),
    SupportedCultures = supportedCultures,
    SupportedUICultures = supportedCultures
    });

    3
    private readonly IStringLocalizer<HomeController> _localizer;
    public HomeController( IStringLocalizer<HomeController> localizer)
    {
    _localizer = localizer;
    }
    public IActionResult Hello()
    {
    return Content(_localizer["Hello"]);
    }
    4.
    Resources/Controllers/HomeController.en-US.resx Hello HELLO
    Resources/Controllers/HomeController.zh-CN.resx Hello 你好

    https://localhost:44398/home/hello
    https://localhost:44398/home/hello?ui-culture=zh-CN
    https://localhost:44398/home/hello?ui-culture=en-US
    ----------------------------------------------------
    视图多语言
    ConfigureServices 1
    services.AddMvc().AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
    2. HomeController
    public IActionResult Hello()
    {
    return View();

    }
    3.
    Views/Home/Hello.zh-CN.resx GoodBye 再见
    4.Hello.cshtml

    @using Microsoft.AspNetCore.Mvc.Localization

    @inject IViewLocalizer Localizer
    @{
    ViewData["Title"] = "Hello";
    }

    <h1>Hello</h1>

    <h2>@Localizer["GoodBye"]</h2>
    4.


    https://localhost:44398/home/hello
    https://localhost:44398/home/hello?ui-culture=zh-CN
    https://localhost:44398/home/hello?ui-culture=en-US

    前端 VUE请求 HEADER 

    const config = {
    headers: {
    "accept-language": "en-US,zh;q=0.9,en;q=0.8"
    }
    }

           axios.post('', '', config)

  • 相关阅读:
    android 单位详解
    ViewFlipper的使用
    today is history,today is tomorrow
    Android2.1 和之后的版本 中的 drawable(hdpi,ldpi,mdpi) 的区别
    auto_ptr
    android编写Service入门
    Android程序完全退出的三种方法
    Android中Toast的用法简介
    安装android开发环境
    error C2850: 'PCH header file'
  • 原文地址:https://www.cnblogs.com/LiuFengH/p/13052183.html
Copyright © 2020-2023  润新知