-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Refactor frontend and backend locale_controllers #4126
Refactor frontend and backend locale_controllers #4126
Conversation
Refactored by: - encapsulating the if statement to the new private method `locale_is_available?` for readability and context - making the `requested_locale` a symbol instead of mapping the `available_locales` to a string during `locale_is_available?` - moving setting of the `session`'s' locale line down one to be consistent with the `backend`'s `locale_controller`
Refactored by: - renaming `locale` to `requested_locale` - encapsulating the if statement to the new private method `locale_is_available?` for readability and context - removing unnecessary `respond_to` and `format.json`
respond_to do |format| | ||
format.json { render json: { locale: I18n.locale }, status: 404 } | ||
end | ||
render json: { locale: I18n.locale }, status: 404 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rails/HttpStatus: Prefer :not_found over 404 to define HTTP status code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I have seen in Solidus, is that only or mainly status codes are used rather than the symbol equivalents. Should this style be turned off or does the core team actually prefer the symbols?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd gradually refactor the codebase following the linter rules when some lines are changed. This way we keep improving the codebase without big refactors that can compromise git history. The trade-off here is not being consistent, which I don't like either. I'd go with the first, if we have a linter setup with Hound (only checks lines changed) we should use it otherwise it doesn't make sense to keep it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to know for the future! Thank you 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not super strong opinion about the linter requested change, so approving this. Thanks! I can't see any change that could be breaking, thanks for this refactor.
respond_to do |format| | ||
format.json { render json: { locale: I18n.locale }, status: 404 } | ||
end | ||
render json: { locale: I18n.locale }, status: 404 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd gradually refactor the codebase following the linter rules when some lines are changed. This way we keep improving the codebase without big refactors that can compromise git history. The trade-off here is not being consistent, which I don't like either. I'd go with the first, if we have a linter setup with Hound (only checks lines changed) we should use it otherwise it doesn't make sense to keep it.
The goal of these changes were to refactor where possible, improve readability and make the
backend
andfrontend
locale_controller
s more consistent with each other.locale_is_available?
for readability and contextrequested_locale
a symbol instead of mapping theavailable_locales
to a string duringlocale_is_available?
session
's' locale line down one to beconsistent with the
backend
'slocale_controller
locale
torequested_locale
locale_is_available?
for readability and contextrespond_to
andformat.json
Checklist: