I'm building a web app that's going to target multiple locales. My app is written in TypeScript using Angular 2.
My user-facing date controls have a rich layout for each of the month/day/year boxes. I'm using some code in my template to order the M/D/Y boxes according to the user's locale (e.g. 'DD/MM/YYYY' for en-CA, 'MM/DD/YYYY' for en-US).
At the moment, I've got a huge array of locales that I defined once (https://stackoverflow.com/a/9893752/106639) and then match the browser language locale to get the formatting string. It feels like a ham-fisted approach for what I'm doing.
95% of what I need to do is within MomentJs, and my controllers and tests work just fine regardless of the formatting string.
Unfortunately, without knowing the formatting string, I don't know how to set the order of my UI components to match the user's expectations (e.g. if I expect DD/MM/YYYY, it doesn't do me much good if everything respects DD/MM/YYYY except the visible UI control).
Moment exposes some locale data (http://momentjs.com/docs/#/i18n/locale-data/), but it seems to be more about locale-specific projections of the actual date rather than the formatting string.
My ideal drop-in solution would be something like moment().localeData().dateFormatString, which would return me "DD/MM/YYYY".
Or, if I seem to be entirely on the wrong track for handling this sort of UI situation, some pointers would be appreciated!