rgsoc-teams
rgsoc-teams copied to clipboard
Move error messages to translation file
We have some custom error messages, for example here. https://github.com/rails-girls-summer-of-code/rgsoc-teams/blob/db178cfe9d65c5c9f4c58e4bcf0d33148a221177/app/models/application_draft.rb#L141-L145
We want to move these custom error messages to the translation file en.yml. In this commit you can see how it is done, for an error message on the Todo model and its user attribute.
Collect all the error messages and put them into the translation file, at the right place.
Further reading: http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models
@aSquare14 The best way to start is by selecting one of the issues with the 'beginner-friendly' label. Like this issue (or click on the yellow label, to see all issues with that label). Even if you are not a beginner at coding, they are suitable for first time contributors. Does this work for you?
After that, if you are looking for something more challenging, you can take a look at the issues labeled 'rgsoc18'. I wouldn't recommend all of them, but we can chat about that later.
To learn more about projects: see https://railsgirlssummerofcode.org/guide/projects/ I don't know much more that what is in the guides ;-) , there is an email address in the guide for further inquiries.
Thank You !
On Fri, Dec 22, 2017 at 2:37 PM, Maud de Vries [email protected] wrote:
@aSquare14 https://github.com/asquare14 The best way to start is by selecting one of the issues with the 'beginner-friendly' label. Like this issue (or click on the yellow label, to see all issues with that label). Even if you are not a beginner at coding, they are suitable for first time contributors. Does this work for you?
After that, if you are looking for something more challenging, you can take a look at the issues labeled 'rgsoc18'. I wouldn't recommend all of them, but we can chat about that later.
To learn more about projects: see https://railsgirlssummerofcode.org/ guide/projects/ I don't know much more that what is in the guides ;-) , there is an email address in the guide for further inquiries.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rails-girls-summer-of-code/rgsoc-teams/issues/878#issuecomment-353554966, or mute the thread https://github.com/notifications/unsubscribe-auth/AV4EVWDVOi1YCr138_XQuFRKmTtUCi1nks5tC3FTgaJpZM4Qlyp3 .
Hey @F3PiX ,I would like to work on the issue,will send a PR soon :)
Hi @nileshgulia1 Welcome at the Teams App!!! Great that you want to contribute. 👍 🎉
@aSquare14 Are you currently working on this issue? Or can we pass it to @nileshgulia1 ?
@nileshgulia1 I'd hate to see you do double work for nothing, so please wait a few days until we know if @aSquare14 is working on this.
Nopes I'm not. He's free to work on it. All the best!
On 27 Dec 2017 9:26 pm, "Maud de Vries" [email protected] wrote:
Hi @nileshgulia1 https://github.com/nileshgulia1 Welcome at the Teams App!!! Great that you want to contribute. 👍 🎉
@aSquare14 https://github.com/asquare14 Are you currently working on this issue? Or can we pass it to @nileshgulia1 https://github.com/nileshgulia1 ?
@nileshgulia1 https://github.com/nileshgulia1 I'd hate to see you do double work for nothing, so please wait a few days until we know if @aSquare14 https://github.com/asquare14 is working on this.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rails-girls-summer-of-code/rgsoc-teams/issues/878#issuecomment-354133693, or mute the thread https://github.com/notifications/unsubscribe-auth/AV4EVQHruWy_n38teJnDQARUwhcSlzIeks5tEmi5gaJpZM4Qlyp3 .
@nileshgulia1 All yours!!! 💃
@aSquare14 Thanks for your swift reaction! Much appreciated.
@nileshgulia1 One more thing: be sure to first pull in the latest changes - we just merged a huge PR - . Then create your branch, so that your commits are on top of the changes. This will save you a lot of merge conflicts later on.
(Ask away if you need more explanation/help.)
hey @F3PiX ,need help translating error messages via i18n.
For translating error messages in app/models/applicaton_draft
def different_projects_required
if project1 && project1 == project2
errors.add(:projects, :must_not_be_selected_twice)
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)
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)
end
end
def different_projects_required if project1 && project1 == project2 errors.add(:projects, :must_not_be_selected_twice) end end
errors:
models:
application_draft:
attributes:
projects:
must_not_be_selected_twice: must not be selected twice
is this the right approach?
This is a great start, yes!
-
The general idea is correct: the original string value becomes the value for the error key. ('must not be selected twice'). I assume the last code block you showed ^ is in the en.yml file. Right? It should be.
-
It is not required per se that the whole sentence becomes the key; main goal is that it is very clear (for your fellow developers) what error message is generated. That is partly a matter of opinion, but generally they can be more concise than the message for the user. I myself like it when the describe the error. For instance, 'must not be selected twice' can be called 'multiple_selection_error'
-
I did not yet check the exact place in the en.yml file. One way to check that yourself is update the test files (with these new error keys') and then run the tests. If you happen to add a error to the wrong place, the tests will fail. (For example, for the Application Draft: some are going to :base, others to :projects.) The tests will tell you!
-
Minor detail: be sure to use lowercase only for the keys. (not
:Only_one_application..., in the third method in your question ^)
Okay?
@F3PiX Great,Thank you :)
Hi @nileshgulia1 How are things going? Let me know if you need help?
Hello,@F3PiX, Got busy doing other work,Yeah things are going great ,Sure i will ask if i need help.Thank you :)