Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Best practices for using globalize and Node.js with express #460
The documentation isn't super clear on this, so I was hoping to get a little clarification/confirmation on the recommended best practices for scenarios using globalize within a node.js app powered by express.
Consider the scenario where an app supports multiple locales, and needs to assign the correct one to each incoming request based on the user's chosen preference. For efficiency, it seems like the best approach is to simply create one Globalize object for each supported locale, and then attach that locale-specific instance to the
Is the right way to do this something like the following?
Or, is it better/possible to create the
Is it necessary to call
All of the examples I've seen only seem to show loading a single locale at a time, so perhaps expanding the docs to discuss this scenario would be helpful for others as well.
And to add to this question, what's the right way to map from a list of supported "locales" to their proper CLDR JSON files? e.g., if my app supports "en-US", "zh-TW", "fr-FR" -- what's the recommended (automatic) way to map those to the correct CLDR files to pass to
Hi @dpolivy, although we've been discussing this in other places (e.g., rxaviers/cldrjs#30), I haven't replied to this issue directly... Improving our documentation with best practices and better examples is of our interest. We're working towards it and all help is very much appreciated.
For optimal performance, you should cache your formatters and parsers per locale.
The CLDR data you load via
The generated formatters and parsers keep its own copy of processed CLDR data (properties). So,
The data loaded by
You can either use the instances or the static methods (that requires setting the global locale using
Globalize should have improved docs and examples to answer to this question. But for now, anyone can find details in the conversation we're having at rxaviers/cldrjs#30 (comment).
Please, just let me know if you still have any questions.
Do you have any suggestion on how we could improve our docs? Thanks