admin管理员组文章数量:1199535
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?
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?
Share Improve this question edited Aug 19, 2015 at 2:52 JasonMArcher 15k22 gold badges58 silver badges53 bronze badges asked May 9, 2011 at 11:37 PacerierPacerier 89.6k111 gold badges383 silver badges644 bronze badges 10- possible duplicate of Internationalization in Javascript – Aron Rotteveel Commented May 9, 2011 at 10:47
- 2 There isn't any universal shortcut, if that's what you're asking. Yes, i18n and l10n is "much work", but that is the solution. Sorry. – Piskvor left the building Commented May 9, 2011 at 11:39
- 2 Believing that just translating all the parts of your date/time string is all you have to do is somehow cute :) – OregonGhost Commented May 9, 2011 at 11:47
- What technology are you using server-side? It may already have anything you'll need. – OregonGhost Commented May 9, 2011 at 11:49
- 1 when it comes to dates, localisation is just as important as internationalisation -- the date formats used in various countries differ wildly. – Spudley Commented May 9, 2011 at 12:01
5 Answers
Reset to default 7Paul 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
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.
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
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.
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
本文标签: javascriptinternationalization of dates on the webStack Overflow
版权声明:本文标题:javascript - internationalization of dates on the web - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738593839a2101672.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论