Skip to content

Commit

Permalink
i18n support for PR #78. The main error checking happens when we call…
Browse files Browse the repository at this point in the history
… Accounts.createUser since that’s where errors are most likely to happen. Error from Meteor.loginWithPassword is very unlikely since we’re logging them in with the account they just created.
  • Loading branch information
dkoo761 committed Feb 11, 2014
1 parent 6fba28d commit 0fb75a4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions client/i18n/english.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ en =
emailRequired: "Email is required"
signupCodeRequired: "Signup code is required"
signupCodeIncorrect: "Signup code is incorrect"
userValidationFailed: "User validation failed"
emailAlreadyExists: "Email already exists."
usernameAlreadyExists: "Username already exists."
unknown: "Unknown error"

i18n.map "en", en
3 changes: 3 additions & 0 deletions client/i18n/german.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ de =
emailRequired: "E-Mail benötigt"
signupCodeRequired: "Registrierungscode benötigt"
signupCodeIncorrect: "Registrierungscode ungültig"
userValidationFailed: "[DE] User validation failed"
emailAlreadyExists: "[DE] Email already exists."
usernameAlreadyExists: "[DE] Username already exists."
unknown: "Unbekannter Fehler"

i18n.map "de", de
3 changes: 3 additions & 0 deletions client/i18n/spanish.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ es =
emailRequired: "Email es necesario"
signupCodeRequired: "Código para suscribir es necesario"
signupCodeIncorrect: "Código para suscribir no coincide"
userValidationFailed: "[SP] User validation failed"
emailAlreadyExists: "[SP] Email already exists."
usernameAlreadyExists: "[SP] Username already exists."
unknown: "Error desconocido"

i18n.map "es", es
14 changes: 11 additions & 3 deletions client/views/signUp/signUp.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
signUpErrorMap = {
'User validation failed': 'error.userValidationFailed',
'Email already exists.': 'error.emailAlreadyExists',
'Username already exists.': 'error.usernameAlreadyExists'
}

Template.entrySignUp.helpers
showEmail: ->
fields = AccountsEntry.settings.passwordSignupFields
Expand Down Expand Up @@ -121,22 +127,24 @@ Template.entrySignUp.events
data.username = username
Accounts.createUser newUserData, (err, data) ->
if err
Session.set('entryError', err.reason)
errorMsg = signUpErrorMap[err.reason]
errorMsg = 'error.unknown' if errorMsg is undefined
Session.set('entryError', i18n(errorMsg))
return
#login on client
if _.contains([
'USERNAME_AND_EMAIL',
'EMAIL_ONLY'], AccountsEntry.settings.passwordSignupFields)
Meteor.loginWithPassword(email, password, (error) ->
if error
Session.set('entryError', error.reason)
Session.set('entryError', i18n("error.unknown"))
else
Router.go AccountsEntry.settings.dashboardRoute
)
else
Meteor.loginWithPassword(username, password, (error) ->
if error
Session.set('entryError', error.reason)
Session.set('entryError', i18n("error.unknown"))
else
Router.go AccountsEntry.settings.dashboardRoute
)
Expand Down

7 comments on commit 0fb75a4

@softwarerero
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I dont like here is that an error I throw in Accounts.validateNewUser results now in 'error.unkown'. Could we preserve user errors, also the accounts modules might throw a lot of other errors and the meaning gets lost.

@queso
Copy link
Contributor

@queso queso commented on 0fb75a4 Feb 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserve how? Not translating it and just tossing the actual error from accounts-base?

@softwarerero
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer only to translate when there is a translation and not everything untranslated just to 'Unknown error' or the like in another language. Better an English error with some meaning than just a generic one.

@queso
Copy link
Contributor

@queso queso commented on 0fb75a4 Feb 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to let you lead this if you want :)

@softwarerero
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I started with a module with translations of accounts errors. I will address this when I have a first version ready.

@dkoo761
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it would be nice not to lose custom validation errors. I didn't think about that use case when implementing this. Thanks @softwarerero!

@softwarerero
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback dkoo761.

Please sign in to comment.