-
Notifications
You must be signed in to change notification settings - Fork 138
Moved error messages to translation file #899
Moved error messages to translation file #899
Conversation
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.
Hi @nileshgulia! Congrats with your first contribution to the RGSoC Teams app! 🎉
This is a great start!
I propose alternatives for the error messages names. In general, we aim for readability, and also keep them in line with the existing Rails error names where possible.
app/models/application_draft.rb
Outdated
@@ -173,19 +173,19 @@ def ready? | |||
|
|||
def different_projects_required | |||
if project1 && project1 == project2 | |||
errors.add(:projects, 'must not be selected twice') | |||
errors.add(:projects, :multiple_sel_error) |
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.
Can we make this: 'too_many_selected' ? For better readability :-) and dev happiness 🎁
Sorry, I know I said to use 'error' in the key before. But now that I see them all together, it doesn't looks so nice.
app/models/application_draft.rb
Outdated
end | ||
end | ||
|
||
def accepted_projects_required | ||
if projects.any? { |p| p && !p.accepted? } # if they don't exist, the presence validation will handle it | ||
errors.add(:projects, 'must have been accepted') | ||
errors.add(:projects, :must_accepted) |
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.
Can we make this: none_accepted
?
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.
yeah,sure 👍
app/models/application_draft.rb
Outdated
end | ||
end | ||
|
||
def only_one_application_draft_allowed | ||
unless team.application_drafts.where(season: season).none? | ||
errors.add(:base, 'Only one application may be lodged') | ||
errors.add(:base, :one_app_allowed) |
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.
Can we make this too_many_applications
?
app/models/application_draft.rb
Outdated
@@ -195,7 +195,7 @@ def set_current_season | |||
|
|||
def students_confirmed? | |||
unless team.present? && team.students.all?{|student| student.confirmed? } | |||
errors.add(:base, 'Please make sure every student confirmed the email address.') | |||
errors.add(:base, :confirmed_email_address) |
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.
How about: unconfirmed_email_address
.
app/models/conference.rb
Outdated
@@ -29,7 +29,7 @@ def date_range | |||
|
|||
def chronological_dates | |||
unless starts_on <= ends_on | |||
errors.add(:ends_on, 'must be a later date than start date') | |||
errors.add(:ends_on, :wrong_date_sel) |
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.
Can we make this more expressive, maybe reference the method name : 'chronology_violation'
config/locales/en.yml
Outdated
application_draft: | ||
attributes: | ||
projects: | ||
must_accepted: must have been accepted |
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.
As this is a yml file, you can collect similar values under the same key. So, you can reuse the keys:
errors:
models:
todo:
.....
application_draft:
from line 86 and 87.
(See for an example how all the time formats are collected in line 6 and after. )
In the same way, you can put the message in line 105 right after the message in current line 99.
That goes for the rest of the file as well. I'll leave that for you to try. So I won't point out all the changes.
Let me know if something is unclear!
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.
Also, can you follow the same indentation as the rest of the file? It seems not to be super consistent, with sometimes 4 and sometimes 2 spaces. At first sight, it looks like it is easy to copy the same indentations.
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.
Thanks for being patient.I need another help :)
models:
todo:
application_draft:
conference:
team:
user:
attributes:
user:
too_many_reviewers: too many reviewers
projects:
too_many_selected: must not be selected twice
none_accepted: must have been accepted
base:
too_many_applications: Only one application may be lodged
unconfirmed_email_address: Please make sure every student confirmed the email address.
ends_on:
chronology_violation: must be a later date than start date
roles:
too_many_students: there cannot be more than 2 students on a team.
github_handle:
immutabilty_violation: can't be changed
What's wrong with this code, my local tests are failing?
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.
No worries :-) We've all been there! I really appreciate your effort.
Take a look at this: http://docs.ansible.com/ansible/latest/YAMLSyntax.html
You should collect the attributes for each key.
Like this:
errors:
models:
todo:
attributes:
user:
too_many_reviewers: too many reviewers
application_draft:
attributes:
projects:
must_accepted: must have been accepted
# other error messages for projects here
#other_attribute:
#error messages on other_attribute
#yet another model:
attributes:
#etc
Does that make sense?
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.
Yes,exactly I have already written the above code you mentioned earlier, but this is not showing in the changes .please check my latest commit 9dba120
.env-example
Outdated
CAMO_KEY=supersecret | ||
|
||
# Google Maps API key for e.g. city autocomplete | ||
GOOGLE_MAPS_API_KEY=YourGoogleMapsAPIKey |
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.
We don't want to remove this file from the repo. (I don't think you need to remove it locally, either 🤔 ).
Anyway, removing it should not be part of this PR.
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.
yes,sorry for that,the file got accidentally removed ,will add it back now :)
config/database.yml.example
Outdated
production: | ||
adapter: postgresql | ||
database: rgsocteams_production | ||
host: localhost |
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.
Same as for the other removed file: we don't want this file removed. Can you leave the removal out of this PR please?
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.
yeah,sure :)
app/models/user.rb
Outdated
@@ -220,7 +220,7 @@ def complete_from_github | |||
|
|||
def immutable_github_handle | |||
return if new_record? | |||
errors.add(:github_handle, "can't be changed") if changes_include?(:github_handle) | |||
errors.add(:github_handle, :can't_be_changed) if changes_include?(:github_handle) | |||
end | |||
|
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.
Remove this whiteline please.
config/locales/en.yml
Outdated
github_handle: | ||
can't_be_changed: can't be changed | ||
|
||
|
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.
And remove the redundant whitelines please
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.
made some changes
.env-example
Outdated
CAMO_KEY=supersecret | ||
|
||
# Google Maps API key for e.g. city autocomplete | ||
GOOGLE_MAPS_API_KEY=YourGoogleMapsAPIKey |
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.
yes,sorry for that,the file got accidentally removed ,will add it back now :)
app/models/application_draft.rb
Outdated
end | ||
end | ||
|
||
def accepted_projects_required | ||
if projects.any? { |p| p && !p.accepted? } # if they don't exist, the presence validation will handle it | ||
errors.add(:projects, 'must have been accepted') | ||
errors.add(:projects, :must_accepted) |
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.
yeah,sure 👍
config/database.yml.example
Outdated
production: | ||
adapter: postgresql | ||
database: rgsocteams_production | ||
host: localhost |
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.
yeah,sure :)
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.
@F3PiX please review
team: | ||
attributes: | ||
roles: | ||
too_many_students: there cannot be more than 2 students on a team. |
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.
For the team, two base errors are missing here. (line 175 and 183)
rgsoc-teams/app/models/team.rb
Lines 165 to 184 in a020e98
MSGS = { | |
duplicate_student_roles_singular: "%s already is a student on another team for #{Season.current.name}.", | |
duplicate_student_roles_plural: "%s already are students on another team for #{Season.current.name}." | |
} | |
def disallow_multiple_student_roles | |
students = User.with_role('student').joins(roles: :team).where(id: roles.map(&:user_id)). | |
where.not('roles.team_id' => id).where('teams.season_id' => season_id) | |
return if students.empty? | |
msg = MSGS[:"duplicate_student_roles_#{students.size == 1 ? 'singular' : 'plural'}"] | |
errors.add :base, msg % students.map(&:name).join(', ') | |
end | |
def disallow_duplicate_members | |
new_members = roles.map { |role| role.user } | |
duplicate_role_users = new_members.find_all { |member| new_members.count(member) > 1 }.uniq | |
return if duplicate_role_users.empty? | |
msg = "%s can't have more than one role in this team!" | |
errors.add :base, msg % duplicate_role_users.map(&:name).join(', ') | |
end |
It is a bit more challenging than the other errors. Are you up to that?
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.
Ohh,I guess I had missed it, I will have a look at 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 jump!
The two unchanged files shouldn't be part of this PR. Depending on how comfortable you are with using git; the quickest solution might be: close this PR, open a new one and copy the changes you made in the files concerning the error messages.
Otherwise : 👍 Great way to say goodbye to the old year ;-)
@F3PiX thanks for the help so far,I will close the PR for now and will submit a clean PR soon :) |
Related issue #878
Error messages are moved to en.yml file.Tests are also passing.