惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Palo Alto Networks Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Schneier on Security
Engineering at Meta
Engineering at Meta
I
InfoQ
L
LangChain Blog
Cyberwarzone
Cyberwarzone
T
Tenable Blog
WordPress大学
WordPress大学
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Last Watchdog
The Last Watchdog
Last Week in AI
Last Week in AI
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
爱范儿
爱范儿
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
AI
AI
T
Tor Project blog
I
Intezer
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
N
News and Events Feed by Topic
Latest news
Latest news
S
Security Affairs
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog RSS Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
S
Securelist

博客园 - 灰灰狼

架构与设计概要 IoC概要 需求分析概要 接上文,支持并发数量的完美版本 消息队列并发处理基类-简化版 2013年5.28~7.27 Microsoft FTE 微软面试总结 String Format for DateTime multi-language 问题观 New life I would like About that task about wcf 基于证书的WCF安全开发详解 asp.net缓存(20100804完善版) - 灰灰狼 - 博客园 呼唤程序员精神——关于我今天发起的讨论的总结 asp.net mvc下实现窗口不关闭,就让Session不过期 正确的产品开发策略
多语言建议
灰灰狼 · 2010-11-02 · via 博客园 - 灰灰狼

我在做涉及到多语言的程序时,发现一些现有程序中可以改进的地方,比如获取用户语言的方法,假如用目前的Language.GetCurrentLanguage()方法,而用户浏览器语言又是系统中不支持的时候,有些RealSearch的东西是搜不出来的,以下两条SQL只有语言参数不同,中文搜不出来,英文可以:

SILCustom_Business_SearchForMatch

      @PageIndex = 1,

      @PageSize = 1,

      @Category = 0,

      @Keywords = '',

      @Scope = 'World',

      @CountryId = 0,

      @BclLanguage = 'zh-CN'

SILCustom_Business_SearchForMatch

      @PageIndex = 1,

      @PageSize = 1,

      @Category = 0,

      @Keywords = '',

      @Scope = 'World',

      @CountryId = 0,

      @BclLanguage = 'en-US'

我做了一些研究,做如下建议(如果有时间,我会做例子):

多语言方案要满足以下需求:

1.       不论在任何地方,均可方便的访问到当前上下文所需要的语言。

现在的方案里,语言的获取操作是在BLL层,这导致Dal的访问必须提供语言参数(如AddBusinessCategoryManagerAssignExtistingBusinessActivityToMultiSelection方法),这不是一种优雅的设计。

2.       尽最大可能找到与用户需求最接近的语言包,实在找不到的时候,提供默认语言,永远不会出异常。

现在的Language类里,只取了客户端所支持的首选语言,并没有尽最大努力去找最匹配的语言,一旦首选语言是系统不支持的,将出异常。

最佳作法是:

1.       定义系统支持的语言列表,此列表指出目前系统所支持的语言,当用户语言不在此列表时,使用默认语言。

2.       获取语言的方法是通过2个阶段:

1)      初始化阶段:用Cookie[“UserLanguage”]保存用户所用语言。

         在Application_BeginRequest中,当Cookie[“UserLanguage”]不为空时,把它赋给Thread.CurrentThread.CurrentCulture Thread.CurrentThread.CurrentUICulture;

Cookie[“UserLanguage”]为空时,需要把客户端支持的且系统也支持的语言赋给Cookie,方法是依次看Request.UserLanguages中所支持的语言,一旦发现有与系统支持的语言相匹配的语言,就将其设置到Cookie,如果找不到,就赋默认语言。同时页面上提供系统所支持语言的列表选项,用户可以自己设置需要查看的语言,选择后系统简单的把所选语言赋到Cookie并刷新页面。

2)      在后续需要获取语言的时候,就用Thread.CurrentThread.CurrentCulture即可,无需传参数。

3.       获取资源时,使用ResourceManager ,这个类会自动根据当前线程语言(CultureInfo.CurrentCulture Thread.CurrentThread.CurrentCulture)去找对应资源。在页面上可以用<%$ Resources:key %>语法显示的访问资源,或用meta:resourcekey="key"隐式的访问资源,在代码里可以用GetLocalResourceObjectGetGlobalResourceObjectResources.Class.Resource来访问资源。Web.config和页面都能定义使用的语言,页面的InitializeCulture()可以被重写来动态设置语言,不过最好的方法还是在Global.asax里的Application_BeginRequest动态设置。