Skip to content
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

Translations Not Working For validation messages from ValidationMessages module #3360

Open
aaronskiba opened this issue Dec 5, 2023 · 4 comments
Assignees

Comments

@aaronskiba
Copy link
Contributor

aaronskiba commented Dec 5, 2023

Please complete the following fields as applicable:

What version of the DMPRoadmap code are you running? (e.g. v2.2.0)

  • v4.1.1

Expected behaviour:

  • Validation messages should render in the same language that is selected within the app.

Actual behaviour:

  • Validation messages where a message: argument is provided (e.g. validates :text, presence: { message: QUESTION_TEXT_PRESENCE_MESSAGE } only appear to render in the default language.
  • When an attribute name is included in a validation message, its name is always in the default language.

Steps to reproduce:

  1. Select a non-default language
  2. Perform any action that triggers a validation messages where a message: argument is provided
  3. Observe the rendered validation message.

Screenshots of some rendered validation messages when the 'Français (CA)' language is selected:

Screenshot 2023-12-05 at 11 18 08 AM
Screenshot 2023-12-05 at 11 19 53 AM
Screenshot 2023-12-05 at 11 27 11 AM

@aaronskiba
Copy link
Contributor Author

aaronskiba commented Dec 5, 2023

Translations of attribute names can be enabled in config/locales/en.yml 4.5 Translations for Active Record Models.

Our validation message translations could be handled in config/locales/en.yml as well: 4.5.1 Error Message Scopes

@aaronskiba aaronskiba self-assigned this Dec 6, 2023
@aalvan
Copy link

aalvan commented May 30, 2024

I'm not sure if this is what you need, but I was able to change the language for both alerts and the platform by changing the following lines of code:

In /roadmap/config/initializers/translation.rb:

 DEFAULT_LOCALE = 'es'

In /roadmap/config/initializers/_dmproadmap.rb:

config.x.locales.default = 'es'

@aaronskiba
Copy link
Contributor Author

Hi @aalvan, thanks for the reply! I'm still encountering some trouble on my end. Here's a bit more context:

Loading development environment (Rails 6.1.7.7)
3.0.5 :001 > I18n.locale = :'fr-FR'
 => :"fr-FR" 
3.0.5 :002 > _("can't be blank")
 => "ne peut être vide" 
3.0.5 :003 > user = User.first.dup
  User Load (1.4ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1  [["LIMIT", 1]]
 => #<User id: nil, firstname: "DMP", surname: "Administrator", email: "dittest@ualberta.ca", created_at: nil, updated_at: nil, other_organisati... 
3.0.5 :004 > user.firstname = ''
 => "" 
3.0.5 :005 > user.surname = ''
 => "" 
3.0.5 :006 > user.org = nil
 => nil 
3.0.5 :007 > user.valid?
  User Exists? (2.3ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2  [["email", "dittest@ualberta.ca"], ["LIMIT", 1]]
  Language Load (1.0ms)  SELECT "languages".* FROM "languages" WHERE "languages"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
 => false 
3.0.5 :008 > user.errors.full_messages
 => 
["Courriel:  n'est pas disponible",
 "Password Ce champ ne peut être vide",
 "Org doit exister",
 "Firstname can't be blank",
 "Surname can't be blank",
 "Org can't be blank"] 
3.0.5 :009 > 

_("can't be blank") translates successfully. But the same isn't the case for the validation messages. Also, here's a screenshot of what is rendered within the app.
Screenshot from 2024-05-30 08-40-06

In particular, it's the validation messages within app/models/concerns/validation_messages.rb that don't seem to be translating.

@aaronskiba
Copy link
Contributor Author

Hi @aalvan, I also tried implementing your changes using 'fr-Fr' for the language. The validation messages successfully translate to French, but now they fail to translate to English. So the issue must be with when switching to non-default app languages.
Screenshot from 2024-05-30 08-52-07
Screenshot from 2024-05-30 09-00-02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants