我在具有本地化功能的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.
我怎样才能做到这一点 ?
@Camilo Terevinto的解决方案可以完美地工作。如果可以帮助任何人,这是完整的解决方案:
查看:
@model Project.Models.item
<h1>@String.Format(Localizer["Max's {0} is {1}"].Value, Model.Name, Model.Color)</h1>
Resx:
Max's {0} is {1} => {0} de Max est {1}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句