English 中文(简体)
WCF: Is there a way to return different datetime serialization based on the http Accept-Language header?
原标题:

I would like my REST service to return a DateTime as:

  • 01-dec-2009 for Accept-Language: en-US
  • 01-dez-2009 for Accept-Language: pt-BR

Thanks!

André Carlucci

问题回答

I would argue that "serialization" means "converting something to text format for interchange/storage" and not to present to a human reader.

By this definition, it must be language independent, and follow the XML serialization convention, or ISO 8601, or a CultureInfo::InvariantCulture. See also http://www.mihai-nita.net/article.php?artID=20051025a

If we don t call it "serialization" then

How are you serializing those DateTimes?

It looks to me like they ve been converted to strings, in which case you should be able to inspect the Request.UserLanguages property and inject the appropriate CultureInfo into an ordinary string.Format() call.

The standard XML serializer uses a culture-agnostic format explained here:

The dateTime is specified in the following form "YYYY-MM-DDThh:mm:ss" where:

  • YYYY indicates the year
  • MM indicates the month
  • DD indicates the day
  • T indicates the start of the required time section
  • hh indicates the hour
  • mm indicates the minute
  • ss indicates the second

Note that these should be in UTC.





相关问题
How does gettext handle dynamic content?

In php (or maybe gettext in general), what does gettext do when it sees a variable to dynamic content? I have 2 cases in mind. 1) Let s say I have <?=$user1?> poked John <?=$user2?>. ...

Explain the Need for Mutexes in Locales, Please

Reading the question Why doesn’t C++ STL support atoi(const string& ) like functions?, I encountered a comment which warned that GCC (at least) has a bug that can slow down multi-threaded ...

How does Vistalizer work

How does Vistalizer manage to override the language limit in Windows Vista Home edition. Which api s does it use to allow installation of Multiple language packages.

Localized exceptions (within a Struts2 app)

I am developing a Struts 2 application with support for multiple languages. If one of the domain objects needs to throw an exception, how can it do so in such a way that the error message is no ...

Rails Globalize plugin help

Has anyone gotten the Globalize plugin to work Rails 2.3.2 or later? If so, could you direct me to some useful info?

热门标签