-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Locale should be returned if locale is default #16
Conversation
Thank you for this PR. This clarifies your issue. I don't think it is a good idea to change this however. Please feel free to disagree. I'm always open to discussion and reopen. |
But does it make sense that it returns undefined once you have a default value and using that default value, even though it is missing from allowed? I think it should NEVER return undefined as this is an unexpected value. It took me some time to troubleshoot this while in fact it is an easy fix. In fact in my opinion it is a no brainer that the default is always allowed by default. In my defense, you cannot expect the user from doing everything right at once so it can help to just accept these stupid mistakes. If you really do not want to (fine by me), it might also be an idea to just add a warning message that default is missing in allowed. In that case, there is no "magic" solving it but the user is still notified and can fix it. The only problem left in that case is that the server still receives an undefined instead of an object.... |
Locale detection has such broad applications that it is hard to assume defaults. It will (should) probably always be instantiated with a custom configuration based on the projects' requirements. When you assume it to fill in some gaps, these gaps are exactly what other's build on.
I definitely support the idea of showing a warning in non-production environments when 'conflicting' configuration options are detected. This should also apply to Would you want create a new PR for this? |
Sidenote: the current default config might indeed not be the most optimal. {
"priority": ["accept-language", "default"],
"default": "en_GB"
} When you only add the |
Actually when I noticed that I was receiving undefined while I did set a default value, I though the middleware plugin was broken as I was expecting to see at least a return of the default value. I think there is no use case where you could return an undefined while a default is set. But yes, it is one of those use cases maybe not many people ever notice. I actually switched from npm locale to yours because I wanted to get locale and language information. That is probably why my initial config was not set correctly from the first time. But the undefined almost made me give up the plugin while when I see the code, it actually is pretty nice. |
Possible fix for issue #15 , where locale was undefined in case the default value was not part of the allowed array. Now it does also check if locale is default value if default is set.
Use case that is not covered by this pull request is when default value is not set (so should default to 'en_GB' as per default.js) and missing from allowed.