本地化与视图中单独的语言文件夹 [英] Localization with separate Language folders within Views

查看:136
本文介绍了本地化与视图中单独的语言文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,这对于在查看每种语言特定的文件夹。 (我知道这是不是做的最好的方式,但它必须是这样现在)结果
例如
/Views/EN/User/Edit.aspx
/Views/US/User/Edit.aspx

I'm trying to have specific folders for each language in Views. (I know this isn't the best way of doing it but it has to be this way for now)
e.g. /Views/EN/User/Edit.aspx /Views/US/User/Edit.aspx

这些将都使用相同的控制器和模型,但对每种语言不同的看法。

These would both use the same controller and model but have different Views for each language.

在我的的Global.asax.cs 我有:

routes.MapRoute(
    "Default", // Route name
    "{language}/{controller}/{action}/{id}", // URL with parameters
    new { language = "en", controller = "Logon", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
    new { language = @"en|us" } // validation
);

这工作正常,但总是指向了同样的观点。结果
如果我把路径Lanagugage文件夹它的工作原理:

This works ok but always points to the same View.
If I put the path to the Lanagugage folder it works:

return View("~/Views/EN/User/Edit.aspx");

但显然,这不是一个很好的办法做到这一点。结果
反正是有得到MVC以正确的语言文件夹看看?

But clearly this isn't a very nice way to do it.
Is there anyway to get MVC to look in the correct language folder?

我知道这是不是在做本地化的最好的方式,但我不能使用资源文件。

I know this isn't the best way of doing Localization but I can't use resource files.

推荐答案

更改视图引擎使用routeparameter

Change the ViewEngine to use a routeparameter

<一个href=\"http://stackoverflow.com/questions/639450/change-lookup-rule-for-views\">http://stackoverflow.com/questions/639450/change-lookup-rule-for-views

修改

由于扫描视图的路径列表是静态的,没有机会通过努力按照上面的链接改变列表中选择取决于某些控制器实例不同的看法。
这看起来更加有希望的起点:

Since the list of paths scanned for the view is static there is no chance to choose different views depending on some controller instance by working changing the list according to the link above. This looks a more promissing starting point:

<一个href=\"http://www.dotnetguy.co.uk/post/2010/01/31/ASPNET-MVC-e28093-Dynamically-Changing-The-Master-Page-%28Theming%29.aspx\" rel=\"nofollow\">http://www.dotnetguy.co.uk/post/2010/01/31/ASPNET-MVC-e28093-Dynamically-Changing-The-Master-Page-%28Theming%29.aspx

这将覆盖到CreateView的渲染chnage的观点。样品改变了母版,但希望它也适用于意见。

It overwrites CreateView to chnage the view rendered. The sample changes the Masterpage, but hopefully it also works for views.

这篇关于本地化与视图中单独的语言文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆