|
|
|
|
<!doctype html>
|
|
|
|
|
<html lang="en" dir="ltr" class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-local-language" data-has-hydrated="false">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<meta name="generator" content="Docusaurus v3.0.0">
|
|
|
|
|
<title data-rh="true">21. 全球化和本地化 | Furion</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:url" content="http://furion.baiqian.ltd/docs/local-language"><meta data-rh="true" property="og:locale" content="en"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="docusaurus_version" content="current"><meta data-rh="true" name="docusaurus_tag" content="docs-default-current"><meta data-rh="true" name="docsearch:version" content="current"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-current"><meta data-rh="true" property="og:title" content="21. 全球化和本地化 | Furion"><meta data-rh="true" name="description" content="📝 模块更新日志"><meta data-rh="true" property="og:description" content="📝 模块更新日志"><link data-rh="true" rel="icon" href="/img/favicon.ico"><link data-rh="true" rel="canonical" href="http://furion.baiqian.ltd/docs/local-language"><link data-rh="true" rel="alternate" href="http://furion.baiqian.ltd/docs/local-language" hreflang="en"><link data-rh="true" rel="alternate" href="http://furion.baiqian.ltd/docs/local-language" hreflang="x-default"><link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Furion RSS Feed">
|
|
|
|
|
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Furion Atom Feed"><link rel="stylesheet" href="/assets/css/styles.3f87a095.css">
|
|
|
|
|
<script src="/assets/js/runtime~main.89709a83.js" defer="defer"></script>
|
|
|
|
|
<script src="/assets/js/main.10e5dc01.js" defer="defer"></script>
|
|
|
|
|
</head>
|
|
|
|
|
<body class="navigation-with-keyboard">
|
|
|
|
|
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return localStorage.getItem("theme")}catch(t){}}();t(null!==e?e:"light")}(),function(){try{const a=new URLSearchParams(window.location.search).entries();for(var[t,e]of a)if(t.startsWith("docusaurus-data-")){var n=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(n,e)}}catch(t){}}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss")}catch(t){}return!1}())</script><div id="__docusaurus"><div class="floatbar_hUWl"><div class="qrcode_sWwE"><img title="微信扫码关注 Furion 官方公众号" src="/img/weixin_qrcode.jpg" style="display:block"><div>❤️ 关注 Furion 微信公众号有惊喜哦!</div></div><div style="display:flex;flex-direction:row-reverse;align-items:flex-start"><div class="title_SD0k">🫠 遇到问题了</div><div class="extend__5i1"><a class="item_Y35a" href="/docs/subscribe"><div style="flex:1"><div class="itemTitle_If_T">⭐️ VIP 服务 ⭐️</div><div class="itemDesc_dp7r">仅需 499 元/年,尊享 365 天项目无忧</div></div><div class="jiantou_mV_o"></div></a><div class="item_Y35a"><div style="flex:1"><div class="itemTitle_If_T">问题反馈</div><div class="itemDesc_dp7r">到 Furion 开源仓库反馈</div></div><div class="jiantou_mV_o"></div></div></div></div></div><div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="#__docusaurus_skipToContent_fallback">Skip to main content</a></div><div class="announcementBar_mb4j" style="background-color:#4623d9;color:yellow" role="banner"><div class="content_knG7 announcementBarContent_xLdY">⭐️ 开通 VIP 服务仅需 499 元/年,尊享 365 天项目无忧 <a href="/docs/subscribe" style="background-color:rgb(199, 29, 36);color:#ffffff;padding:1px 10px;border-radius:3px;text-decoration:none;display:inline-block;margin:0 5px;font-size:12px;cursor:pointer;">立即开通</a>⭐️</div></div><nav aria-label="Main" class="navbar navbar--fixed-top navbarHideable_m1mJ"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><div class="navbar__logo"><img src="/img/furionlogo.png" alt="Furion Logo" class="themedComponent_mlkZ themedComponent--light_NVdE"><img src="/img/furionlogo.png" alt="Furion Logo" class="themedComponent_mlkZ themedComponent--dark_xIcU"></div><b class="navbar__title text--truncate">Furion</b></a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/category/appendix">文档</a><a class="navbar__item navbar__link" href="/docs/global/app">静态类</a><a class="navbar__item navbar__link" href="/docs/settings/appsettings">配置</a><a class="navbar__item navbar__link" href="/blog">博客</a><div class="navbar__item dropdown dropdown--hoverable"><a href="#" aria-haspopup="true" aria-expanded="false" role="button" class="navbar__link">更新日志</a><ul class="dropdown__menu"><li><a class="dropdown__link" href="/docs/upgrade">📝 查看日志(v4.9.1.7)</a></li><li><a class="dropdown__link" href="/docs/target">🚀 路线图</a></li></ul></div><a href="http://furion.baiqian.ltd/api/api" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">API<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></div><div class="navbar__items navbar__it
|
|
|
|
|
<li>
|
|
|
|
|
<p><strong>新特性</strong></p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li> <label class="label_p8vM" title="新增" style="background-color:#39b54a"><svg viewBox="0 0 1024 1024" width="14px" height="14px" style="display:block" class="icon_knQK"><path d="M512 71.68c-242.688 0-440.32 197.632-440.32 440.32s197.632 440.32 440.32 440.32 440.32-197.632 440.32-440.32-197.632-440.32-440.32-440.32z m0 819.2c-208.896 0-378.88-169.984-378.88-378.88s169.984-378.88 378.88-378.88 378.88 169.984 378.88 378.88-169.984 378.88-378.88 378.88z" fill="white"></path><path d="M542.72 261.12H481.28v220.16H261.12v61.44h220.16v220.16h61.44v-220.16h220.16V481.28h-220.16z" fill="white"></path></svg> <!-- -->新增</label> 多语言支持 <code>L.GetDefaultCulture()</code> 获取本地配置默认语言 <sup>4.8.8.49</sup> <sup>⏱️2023.10.25</sup> <a href="https://gitee.com/dotnetchina/Furion/pulls/858" target="_blank" rel="noopener noreferrer">!858</a></li>
|
|
|
|
|
<li> <label class="label_p8vM" title="新增" style="background-color:#39b54a"><svg viewBox="0 0 1024 1024" width="14px" height="14px" style="display:block" class="icon_knQK"><path d="M512 71.68c-242.688 0-440.32 197.632-440.32 440.32s197.632 440.32 440.32 440.32 440.32-197.632 440.32-440.32-197.632-440.32-440.32-440.32z m0 819.2c-208.896 0-378.88-169.984-378.88-378.88s169.984-378.88 378.88-378.88 378.88 169.984 378.88 378.88-169.984 378.88-378.88 378.88z" fill="white"></path><path d="M542.72 261.12H481.28v220.16H261.12v61.44h220.16v220.16h61.44v-220.16h220.16V481.28h-220.16z" fill="white"></path></svg> <!-- -->新增</label> 多语言支持 <code>L.GetString(name, culture)</code> 获取指定区域翻译 <sup>4.8.8.41</sup> <sup>⏱️2023.08.04</sup> <a href="https://gitee.com/dotnetchina/Furion/commit/044b0edfbd622c7c69d685267aafa9f5855a9167" target="_blank" rel="noopener noreferrer">044b0ed</a></li>
|
|
|
|
|
<li> <label class="label_p8vM" title="新增" style="background-color:#39b54a"><svg viewBox="0 0 1024 1024" width="14px" height="14px" style="display:block" class="icon_knQK"><path d="M512 71.68c-242.688 0-440.32 197.632-440.32 440.32s197.632 440.32 440.32 440.32 440.32-197.632 440.32-440.32-197.632-440.32-440.32-440.32z m0 819.2c-208.896 0-378.88-169.984-378.88-378.88s169.984-378.88 378.88-378.88 378.88 169.984 378.88 378.88-169.984 378.88-378.88 378.88z" fill="white"></path><path d="M542.72 261.12H481.28v220.16H261.12v61.44h220.16v220.16h61.44v-220.16h220.16V481.28h-220.16z" fill="white"></path></svg> <!-- -->新增</label> 多语言支持 <code>DateTime</code> 时间格式化配置节点 <code>DateTimeFormatCulture</code> <sup>4.8.7.31</sup> <sup>⏱️2023.03.31</sup> <a href="https://gitee.com/dotnetchina/Furion/issues/I6RUOU" target="_blank" rel="noopener noreferrer">#I6RUOU</a></li>
|
|
|
|
|
<li> <label class="label_p8vM" title="新增" style="background-color:#39b54a"><svg viewBox="0 0 1024 1024" width="14px" height="14px" style="display:block" class="icon_knQK"><path d="M512 71.68c-242.688 0-440.32 197.632-440.32 440.32s197.632 440.32 440.32 440.32 440.32-197.632 440.32-440.32-197.632-440.32-440.32-440.32z m0 819.2c-208.896 0-378.88-169.984-378.88-378.88s169.984-378.88 378.88-378.88 378.88 169.984 378.88 378.88-169.984 378.88-378.88 378.88z" fill="white"></path><path d="M542.72 261.12H481.28v220.16H261.12v61.44h220.16v220.16h61.44v-220.16h220.16V481.28h-220.16z" fill="white"></path></svg> <!-- -->新增</label> <strong>多语言支持 <code>.json</code> 文件配置方式(推荐)</strong> <sup>4.8.6</sup> <sup>⏱️2023.02.08</sup> <a href="https://gitee.com/dotnetchina/Furion/issues/I6DL71" target="_blank" rel="noopener noreferrer">#I6DL71</a> <a href="https://gitee.com/dotnetchina/Furion/issues/I5DXKP" target="_blank" rel="noopener noreferrer">#I5DXKP</a></li>
|
|
|
|
|
<li> <label class="label_p8vM" title="新增" style="background-color:#39b54a"><svg viewBox="0 0 1024 1024" width="14px" height="14px" style="display:block" class="icon_knQK"><path d="M512 71.68c-242.688 0-440.32 197.632-440.32 440.32s197.632 440.32 440.32 440.32 440.32-197.632 440.32-440.32-197.632-440.32-440.32-440.32z m0 819.2c-208.896 0-378.88-169.984-378.88-378.88s169.984-378.88 378.88-378.88 378.88 169.984 378.88 378.88-169.984 378.88-378.88 378.88z" fill="white"></path><path d="M542.72 261.12H481.28v220.16H261.12v61.44h220.16v220.16h61.44v-220.16h220.16V481.28h-220.16z" fill="white"></path></svg> <!-- -->新增</label> <code>L.SetCurrentUICulture(culture)</code> 和 <code>L.GetCurrentUICulture()</code> 静态方法,可在运行时动态修改当前线程区域性 <sup>4.8.3.10</sup> <sup>⏱️2022.12.23</sup> <a href="https://gitee.com/dotnetchina/Furion/issues/I66JWA" target="_blank" rel="noopener noreferrer">#I66JWA</a></li>
|
|
|
|
|
<li> <label class="label_p8vM" title="新增" style="background-color:#39b54a"><svg viewBox="0 0 1024 1024" width="14px" height="14px" style="display:block" class="icon_knQK"><path d="M512 71.68c-242.688 0-440.32 197.632-440.32 440.32s197.632 440.32 440.32 440.32 440.32-197.632 440.32-440.32-197.632-440.32-440.32-440.32z m0 819.2c-208.896 0-378.88-169.984-378.88-378.88s169.984-378.88 378.88-378.88 378.88 169.984 378.88 378.88-169.984 378.88-378.88 378.88z" fill="white"></path><path d="M542.72 261.12H481.28v220.16H261.12v61.44h220.16v220.16h61.44v-220.16h220.16V481.28h-220.16z" fill="white"></path></svg> <!-- -->新增</label> <code>L.SetCulture(culture, immediately)</code> 方法重载,可配置运行时修改多语言立即有效 <sup>4.8.3.10</sup> <sup>⏱️2022.12.23</sup> <a href="https://gitee.com/dotnetchina/Furion/issues/I66JWA" target="_blank" rel="noopener noreferrer">#I66JWA</a></li>
|
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<p><strong>其他更改</strong></p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li> <label class="label_p8vM" title="调整" style="background-color:#333"><svg viewBox="0 0 1024 1024" width="14px" height="14px" style="display:block" class="icon_knQK"><path d="M380.15463648 874.54223633c0 18.12744166-14.83154297 32.95898463-32.95898463 32.95898463s-32.95898463-14.83154297-32.95898462-32.95898463V228.9152832L172.71078883 370.86962865a33.04467773 33.04467773 0 0 1-46.60400416 0 33.04467773 33.04467773 0 0 1 0-46.6040034l197.55615234-198.14941406A32.76782227 32.76782227 0 0 1 347.0967749 116.52514674c0.03295924 0 0.06591772-0.03295924 0.09887695-0.03295924 1.54907201 0 2.90039088 0.69213867 4.41650366 0.88989258 2.66967773 0.39550781 5.40527318 0.59326172 7.94311548 1.61499049 12.03002904 4.94384766 20.59936549 16.71020508 20.59936549 30.45410156v725.0910642z m320.15698192 23.34155248a32.85351537 32.85351537 0 0 1-23.43383789 9.59106445c-0.03295924 0-0.06591772 0.03295924-0.09887696 0.03295924-1.54907201 0-2.90039088-0.69213867-4.41650365-0.92285182-2.70263697-0.36254857-5.40527318-0.56030248-7.94311549-1.61498972-12.03002904-4.91088842-20.59936549-16.67724584-20.59936473-30.42114309V149.45776367c0-18.12744166 14.83154297-32.95898463 32.95898387-32.95898463s32.95898463 14.83154297 32.95898463 32.95898463v645.60058619l141.52587916-141.92138697c12.81445313-12.82104467 33.81591797-12.82104467 46.63037109 0 12.78808619 12.81445313 12.78808619 33.77636719 0 46.60400416L700.3116184 897.88378881z" fill="white"></path></svg> <!-- -->调整</label> 多语言中间件 <code>app.UseAppLocalization()</code> 添加 <code>Action<options></code> 委托参数 <sup>4.8.7.30</sup> <sup>⏱️2023.03.31</sup> <a href="https://gitee.com/dotnetchina/Furion/issues/I6RUOU" target="_blank" rel="noopener noreferrer">#I6RUOU</a></li>
|
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<p><strong>文档</strong></p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li> <label class="label_p8vM" title="新增" style="background-color:#39b54a"><svg viewBox="0 0 1024 1024" width="14px" height="14px" style="display:block" class="icon_knQK"><path d="M512 71.68c-242.688 0-440.32 197.632-440.32 440.32s197.632 440.32 440.32 440.32 440.32-197.632 440.32-440.32-197.632-440.32-440.32-440.32z m0 819.2c-208.896 0-378.88-169.984-378.88-378.88s169.984-378.88 378.88-378.88 378.88 169.984 378.88 378.88-169.984 378.88-378.88 378.88z" fill="white"></path><path d="M542.72 261.12H481.28v220.16H261.12v61.44h220.16v220.16h61.44v-220.16h220.16V481.28h-220.16z" fill="white"></path></svg> <!-- -->新增</label> <strong>多语言 <code>.json</code> 配置方式文档</strong></li>
|
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
</ul></div></div></div></div></details>
|
|
|
|
|
<!-- -->
|
|
|
|
|
<!-- -->
|
|
|
|
|
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="211-全球化和本地化">21.1 全球化和本地化<a href="#211-全球化和本地化" class="hash-link" aria-label="Direct link to 21.1 全球化和本地化" title="Direct link to 21.1 全球化和本地化"></a></h2>
|
|
|
|
|
<p><strong>全球化</strong> 是设计支持不同区域性的应用程序的过程。 全球化添加了对一组有关特定地理区域的已定义语言脚本的输入、显示和输出支持。</p>
|
|
|
|
|
<p><strong>本地化</strong> 是将已经针对可本地化性进行处理的全球化应用调整为特定的区域性/区域设置的过程。</p>
|
|
|
|
|
<p>通俗来说,就是使应用或系统支持多语言切换。<code>Furion</code> 框架提供了完整支持多语言处理的服务。</p>
|
|
|
|
|
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="212-注册服务">21.2 注册服务<a href="#212-注册服务" class="hash-link" aria-label="Direct link to 21.2 注册服务" title="Direct link to 21.2 注册服务"></a></h2>
|
|
|
|
|
<p>在使用多语言服务之前,必须先注册服务,如:</p>
|
|
|
|
|
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token keyword" style="font-style:italic">public</span><span class="token plain"> </span><span class="token return-type class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">ConfigureServices</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token class-name" style="color:rgb(255, 203, 107)">IServiceCollection</span><span class="token plain"> services</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> services</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">AddControllersWithViews</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></span><br></span><span class="token-line theme-code-block-highlighted-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">AddAppLocalization</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// 注册多语言</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain" style="display:inline-block"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token keyword" style="font-style:italic">public</span><span class="token plain"> </span><span class="token return-type class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">Configure</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token class-name" style="color:rgb(255, 203, 107)">IApplicationBuilder</span><span class="token plain"> app</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><s
|
|
|
|
|
<div class="theme-admonition theme-admonition-important admonition_xJq3 alert alert--info"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg></span>特别注意</div><div class="admonitionContent_BuS1"><p><code>app.UseAppLocalization();</code> 必须在 <code>app.UseRouting();</code> 之前注册。</p></div></div>
|
|
|
|
|
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="213-如何使用">21.3 如何使用<a href="#213-如何使用" class="hash-link" aria-label="Direct link to 21.3 如何使用" title="Direct link to 21.3 如何使用"></a></h2>
|
|
|
|
|
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="2131-配置-localizationsettings">21.3.1 配置 <code>LocalizationSettings</code><a href="#2131-配置-localizationsettings" class="hash-link" aria-label="Direct link to 2131-配置-localizationsettings" title="Direct link to 2131-配置-localizationsettings"></a></h3>
|
|
|
|
|
<p>添加 <code>LocalizationSettings</code> 配置选项:</p>
|
|
|
|
|
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">{</span></span><br></span><span class="token-line theme-code-block-highlighted-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> "LocalizationSettings": {</span></span><br></span><span class="token-line theme-code-block-highlighted-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> "SupportedCultures": ["zh-CN", "en-US"], // 配置支持的语言列表</span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> "DefaultCulture": "zh-CN" // 配置默认语言,如果不配置,取 SupportedCultures 的第一项</span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> }</span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">}</span></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
|
|
|
|
|
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="2132-创建-resources-文件夹">21.3.2 创建 <code>Resources</code> 文件夹<a href="#2132-创建-resources-文件夹" class="hash-link" aria-label="Direct link to 2132-创建-resources-文件夹" title="Direct link to 2132-创建-resources-文件夹"></a></h3>
|
|
|
|
|
<p>接下来在 <code>Web启动项目层</code> 添加 <code>Resources</code> 文件夹,如图:(<strong>可配置放置任意层,见配置 <code>AssemblyName</code></strong>)</p>
|
|
|
|
|
<img src="/img/lang1.png">
|
|
|
|
|
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="214-l-静态类">21.4 <code>L</code> 静态类<a href="#214-l-静态类" class="hash-link" aria-label="Direct link to 214-l-静态类" title="Direct link to 214-l-静态类"></a></h2>
|
|
|
|
|
<p><code>Furion</code> 框架主要通过 <code>L</code> 静态类完成多语言转换,该静态类有以下属性和方法:</p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li><strong><code>L.Text[文本]</code></strong>:转换文本多语言</li>
|
|
|
|
|
<li><strong><code>L.Html[HTML代码, 格式化]</code></strong>:转换 <code>Html</code> 多语言</li>
|
|
|
|
|
<li><code>L.TextOf<T>()[文本]</code>:转换文本多语言,使用该方式那么资源文件需使用完整类型限定名,Furion 4.8.6+ 支持</li>
|
|
|
|
|
<li><code>L.HtmlOf<T>()[HTML代码, 格式化]</code>:转换 <code>Html</code> 多语言,使用该方式那么资源文件需使用完整类型限定名,Furion 4.8.6+ 支持</li>
|
|
|
|
|
<li><code>L.SetCulture(区域码)</code>:设置当前语言区域,默认在下一次请求有效,第二个参数设置 <code>true</code> 立即有效</li>
|
|
|
|
|
<li><code>L.GetSelectCulture()</code>:获取当前的语言区域</li>
|
|
|
|
|
<li><code>L.GetCultures()</code>:获取系统支持的多语言列表</li>
|
|
|
|
|
<li><code>L.SetCurrentUICulture(区域码)</code>:运行时设置当前线程语言区域,立即有效,<code>Furion 4.8.3.10+</code> 版本有效</li>
|
|
|
|
|
<li><code>L.GetCurrentUICulture()</code>: 获取当前线程 UI 区域性,<code>Furion 4.8.3.10+</code> 版本有效</li>
|
|
|
|
|
<li><code>L.GetString<T>(u => u.属性)</code>: 根据表达式获取翻译,<code>Furion 4.8.3.10+</code> 版本有效</li>
|
|
|
|
|
<li><code>L.GetString(name, culture)</code>: 获取指定的区域翻译,<code>Furion 4.8.8.41+</code> 版本有效</li>
|
|
|
|
|
<li><code>L.GetDefaultCulture()</code>: 获取本地配置默认语言,<code>Furion 4.8.8.49+</code> 版本有效</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<div class="theme-admonition theme-admonition-tip admonition_xJq3 alert alert--success"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 12 16"><path fill-rule="evenodd" d="M6.5 0C3.48 0 1 2.19 1 5c0 .92.55 2.25 1 3 1.34 2.25 1.78 2.78 2 4v1h5v-1c.22-1.22.66-1.75 2-4 .45-.75 1-2.08 1-3 0-2.81-2.48-5-5.5-5zm3.64 7.48c-.25.44-.47.8-.67 1.11-.86 1.41-1.25 2.06-1.45 3.23-.02.05-.02.11-.02.17H5c0-.06 0-.13-.02-.17-.2-1.17-.59-1.83-1.45-3.23-.2-.31-.42-.67-.67-1.11C2.44 6.78 2 5.65 2 5c0-2.2 2.02-4 4.5-4 1.22 0 2.36.42 3.22 1.19C10.55 2.94 11 3.94 11 5c0 .66-.44 1.78-.86 2.48zM4 14h5c-.23 1.14-1.3 2-2.5 2s-2.27-.86-2.5-2z"></path></svg></span>小提示</div><div class="admonitionContent_BuS1"><p>通过 <code>L.SetCulture</code> 实际上是往客户端写入区域 <code>Cookie</code> 数据,也就是只对下一次请求有效,如果希望运行时立即有效,可通过 <code>L.SetCurrentUICulture</code> 设置或一起设置即可。</p><p>也可以直接通过设置 <code>L.SetCulture(区域码, true)</code> 立即生效(包含当前请求(线程)和下一次请求)。</p></div></div>
|
|
|
|
|
<h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="215-使用例子">21.5 使用例子<a href="#215-使用例子" class="hash-link" aria-label="Direct link to 21.5 使用例子" title="Direct link to 21.5 使用例子"></a></h2>
|
|
|
|
|
<p>通过上面的配置步骤之后,我们就可以通过 <code>L</code> 静态类在代码任何位置使用了,如:</p>
|
|
|
|
|
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="2151-在类中使用">21.5.1 在类中使用<a href="#2151-在类中使用" class="hash-link" aria-label="Direct link to 21.5.1 在类中使用" title="Direct link to 21.5.1 在类中使用"></a></h3>
|
|
|
|
|
<div class="language-cs codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-cs codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// 文本多语言</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">var</span><span class="token plain"> apiInterface </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> L</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">Text</span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token string" style="color:rgb(195, 232, 141)">"API 接口"</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">var</span><span class="token plain"> sourceCode </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> L</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">Text</span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token string" style="color:rgb(195, 232, 141)">"源码地址"</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token class-name keyword" style="color:rgb(255, 203, 107);font-style:italic">var</span><span class="token plain"> other </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> L</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">Text</span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token string" style="color:rgb(195, 232, 141)">"其他{0}"</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">"的"</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain" style="display:inline-block"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// HTML 标记多语言</span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style=
|
|
|
|
|
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="2152-在视图中使用">21.5.2 在视图中使用<a href="#2152-在视图中使用" class="hash-link" aria-label="Direct link to 21.5.2 在视图中使用" title="Direct link to 21.5.2 在视图中使用"></a></h3>
|
|
|
|
|
<div class="language-html codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#bfc7d5;--prism-background-color:#292d3e"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-html codeBlock_bY9V thin-scrollbar" style="color:#bfc7d5;background-color:#292d3e"><code class="codeBlockLines_e6Vv codeBlockLinesWithNumbering_o6Pm"><span class="token-line theme-code-block-highlighted-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain">@using Furion.Localization</span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain" style="display:inline-block"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"></span><span class="token tag punctuation" style="color:rgb(199, 146, 234)"><</span><span class="token tag" style="color:rgb(255, 85, 114)">div</span><span class="token tag" style="color:rgb(255, 85, 114)"> </span><span class="token tag special-attr attr-name" style="color:rgb(255, 203, 107)">style</span><span class="token tag special-attr attr-value punctuation attr-equals" style="color:rgb(199, 146, 234)">=</span><span class="token tag special-attr attr-value punctuation" style="color:rgb(199, 146, 234)">"</span><span class="token tag special-attr attr-value value css language-css property" style="color:rgb(255, 85, 114)">text-align</span><span class="token tag special-attr attr-value value css language-css punctuation" style="color:rgb(199, 146, 234)">:</span><span class="token tag special-attr attr-value value css language-css" style="color:rgb(255, 85, 114)">center</span><span class="token tag special-attr attr-value value css language-css punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token tag special-attr attr-value value css language-css property" style="color:rgb(255, 85, 114)">margin-top</span><span class="token tag special-attr attr-value value css language-css punctuation" style="color:rgb(199, 146, 234)">:</span><span class="token tag special-attr attr-value value css language-css number" style="color:rgb(247, 140, 108)">50</span><span class="token tag special-attr attr-value value css language-css unit" style="color:rgb(255, 85, 114)">px</span><span class="token tag special-attr attr-value value css language-css punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token tag special-attr attr-value punctuation" style="color:rgb(199, 146, 234)">"</span><span class="token tag punctuation" style="color:rgb(199, 146, 234)">></span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token tag punctuation" style="color:rgb(199, 146, 234)"><</span><span class="token tag" style="color:rgb(255, 85, 114)">p</span><span class="token tag punctuation" style="color:rgb(199, 146, 234)">></span><span class="token plain">让 .NET 开发更简单,更通用,更流行。</span><span class="token tag punctuation" style="color:rgb(199, 146, 234)"></</span><span class="token tag" style="color:rgb(255, 85, 114)">p</span><span class="token tag punctuation" style="color:rgb(199, 146, 234)">></span><span class="token plain"></span></span><br></span><span class="token-line codeLine_lJS_" style="color:#bfc7d5"><span class="codeLineNumber_Tfdd"></span><span class="codeLineContent_feaV"><span class="token plain"> </span><span class="token tag punctuation" style="color:rgb(199, 146, 234)"><</span><span class="token tag" style="color:rgb(255, 85, 114)">p</span><span class="token tag punctuation" style="color:rgb(199, 146, 234)">></span><span class="token plain"></span></span><br></span><span class="token-line theme-c
|
|
|
|
|
<h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="2153-在验证特性中使用">21.5.3 在验证特性中使用<a href="#2153-在验证特性中使用" class="hash-link" aria-label="Direct link to 21.5.3 在验证特性中使用" title="Direct link to 21.5.3 在验证 |