【发布时间】:2023-03-14 18:45:01
【问题描述】:
我在一个带有本地化和本地化功能的 Asp.net Core MVC 网站上工作 我有一个文本要显示,里面有变量:
@{var item = "car"}
<h1>Max's @item is blue</h1>
但在法语中是
@{var item = "la voiture"}
<h1>@item de Max est bleue</h1>
所以单词的顺序改变了,我试试:
@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
<h1>@String.Format(Localizer["Max's {0} is blue"],@item)</h1>
带翻译:
Max's {0} is blue => {0} de Max est bleu
但我有一个错误:
FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
我该怎么做?
【问题讨论】:
-
试试
Localizer["Max's {0} is blue"].Value,@item
标签: c# razor asp.net-core asp.net-core-mvc asp.net-core-localization