问题
Does anyone have any good "architecture" for the internationalization of dates? like in English its Monday, Chinese: 星期一, Dutch: maandag, Japanese: 月曜日
So my first idea is to create some sort of class that stores the strings of Monday to Sunday in 59 different languages. Apparently this isn't scalable at all, imagine now I need to display "12:34 A.M, Monday, 1st Jan 2000" I will then need another translation for A.M, P.M, the months (both long and short forms), the ordinals, etc, etc.
It's too much work, what's the solution?
回答1:
The approach you suggest is not scalable. The Microsoft approach deals with 350 cultures; it has been suggested that there are 160 globally traded currencies etc. Maintaining a class that deals with this range of possibilities is a potential nightmare in the making.
@Aron suggests that your question is a duplicate of Internationalization in Javascript. One of the links in an answer to that question suggests a scalable and maintainable way forward. I would not normally advocate a Microsoft approach, but in this case they do seem to have the right idea for an architecture. Separate out the locale specific material into classes that can be incorporated into your application. Reference the locale specific material by a key based only on the culture (or locale). Don't attempt to maintain culture specific material yourself - unless you HAVE to, you really don't want to go there.
回答2:
Paul Irish said
date.js was abandoned and the version on the homepage is buggy.
and
moment.js is supergood and should be your first pick for date parsing, manip and formatting.
So I guess you people looking for a reliable date javascript library with i18n should use moment.js
回答3:
Datejs should be able to do what you are trying to do:
http://code.google.com/p/datejs/
Getting Started With Datejs
Its a javascript date library with about 157 different date-cultures/languages supported.
They took the approach of having a separate .js file for each culture. See: datejs source - trunk/src/globalization
回答4:
Much better handled on the server side. ASP.NET, for example, provides support for converting dates to strings in at least 30 or 40 different languages. I don't know about other server languages.
回答5:
I advise you to have a look at the jQuery framework which can solve your problem without having to re-inventing the wheel: http://jqueryui.com/demos/datepicker/#localization
Note: jquery-ui is a add-on framework which contains plenty of UI components.
Hope this helps
来源:https://stackoverflow.com/questions/5936330/internationalization-of-dates-on-the-web