asp.net mvc 本地化 [英] asp.net mvc localization

查看:23
本文介绍了asp.net mvc 本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用路由实现本地化

I'm trying to implement localization with routes

我有以下几点:

routes.MapRoute( "DefaultLocalized", 
                 "{lang}/{controller}/{action}/{id}",
                 new { controller = "Home",
                       action = "Index",
                       id = "",
                       lang = "en" }
               );

routes.MapRoute( "Default",
                 "{controller}/{action}/{id}",
                 new { controller = "Home",
                       action = "Index",
                       id = "" }
               );

当我调用我的页面 domain/en/home/index 时,它工作正常,但是当我调用 domain/home/index 时,我收到错误 404:资源不能找到了.

When I call my page domain/en/home/index, it works fine but when i call domain/home/index I get error 404: resource cannot be found.

此外,当我在 domain/en/home/index 并单击安全页面时,我被重定向到 domain/Account/login 我如何被重定向domain/en/Account/login?

Also when I'm at domain/en/home/index and I click a secured page I get redirected to domain/Account/login how can I be redirected to domain/en/Account/login?

此外,当我收到应用程序错误时,如何将我重定向到 domain/en/home/error?

Also when I get an application error how can I be redirected to domain/en/home/error?

真正的问题是如何将语言作为路由参数来实现本地化?

The real question is how can I implement localization with language as a route parameter?

推荐答案

您还可以引入比 Marc Gravell 和 Freddy Rios 更严格的约束.

You could also introduce a constraint even tighter than Marc Gravell and Freddy Rios.

类似于en|de|fr|es".这意味着对语言进行硬编码,但通常这些语言很少且已知.

something like "en|de|fr|es". This would mean hardcoding the languages but usually these are few and known.

这篇关于asp.net mvc 本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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