首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用接受语言头的默认内容的RFC2616算法

使用接受语言头的默认内容的RFC2616算法
EN

Stack Overflow用户
提问于 2014-06-07 13:00:26
回答 1查看 240关注 0票数 0

我正在设计一个将内容存储在数据库中的web服务,我希望确保该设计符合RFC2616。然而,我有点不清楚正确的方式来匹配内容。

如果我将行为指定为用户故事:

代码语言:javascript
复制
Given I request content in 'en_GB'
When the server has content in 'en_US' 
     and the server has content in 'en_CA'
     and the server does not have content in 'en'
Then the server should return content in '???'

问题:服务器应该以什么语言返回内容?

Update:基于pawel的回答,我认为这些故事应该如下所示:

代码语言:javascript
复制
Given I request content in 'en_GB'
When the server has content in 'en_US' 
     and the server has content in 'en_CA'
     and the server has content in 'en'
Then the server should return content in 'en'

Given I request content in 'en_GB'
When the server has content in 'en_US' 
     and the server has content in 'en_CA'
     and the server does not have content in 'en'
Then the server should return content in the server default language
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-07 15:36:21

你想要的是一个地方的退路。对于HTTP语言报头,I18n最佳实践规则是:

  1. 给定lang-country对返回内容(如果是可用的)。
  2. 然后尝试返回给定语言的内容(如果可用的话)。
  3. 然后尝试列表上的下一种语言(从1开始)
  4. 如果到目前为止没有任何工作,则返回(应用程序\服务器)默认语言。

例如,假设应用程序包含德语翻译(de)和HTTP接受语言标题,如下所示:

接受-语言: fr-FR,de-AT;q=0.7

返回的语言应该是德语。

回到您的问题上,您应该返回的是默认的区域设置。显然,对于给定的语言有共同的资源是很好的(在本例中是en)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24097467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档