我正在将 AdminLTE MVC 与 Visual Studio 一起使用。我想实现多语言系统,一种方法似乎是使用 RESX 文件。
我网站的默认语言是法语 (fr)。因此,我创建了 2 个文件并将它们保存在我的“/Resources/”文件夹中:
我在每个 RESX 文件上指定了“PublicResXFileCodeGenerator”属性。
然后,在我的RouteConfig.cs文件中,我添加了一个新的routes.MapRoutes以使用类似 www.mywebsite.com/fr/MyController 的语言生成 url:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
/* routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);*/
routes.MapRoute(
name: "ML",
url: "{lang}/{controller}/{action}/{id}",
defaults: new { lang = "fr", controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
对于一个简单的测试,我只在我的 RESX 文件中添加了 1 个变量。对于法语版本:
然后,在我的视图 Index.cshtml 中,我只显示“Valeur”值的内容:
@using Resources;
@{
ViewBag.Title = "Index";
ViewBag.Description = "Home Page";
}
<div>
The current Value is : <b>@Resources.CDV.Valeur</b>
</div>
当我调用 /en/ 页面时,未加载 CDV.en.resx:
你知道我做错了什么吗?
谢谢。