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

Message translations not working with craft.formie.renderForm #2163

Open
romainpoirier opened this issue Nov 28, 2024 · 4 comments
Open

Message translations not working with craft.formie.renderForm #2163

romainpoirier opened this issue Nov 28, 2024 · 4 comments

Comments

@romainpoirier
Copy link

Describe the bug

Describe the bug:

I'm using Formie 3.0.12 and attempting to translate messages for a form rendered with {{ craft.formie.renderForm('donation') }}.

I created a translation file at /translations/fr/formie.php, containing all the keys from vendor/verbb/formie/src/translations/en/formie.php (following the documentation). However, these translations are not being applied to the error messages.

Note: The Craft site’s language is configured as French (fr), and I have confirmed that other translations (e.g., for templates and fields) are working as expected.

Expected behavior:

The error messages should be translated into French based on the keys in the /translations/fr/formie.php file.

Actual behavior:

The messages remain in English, even though the corresponding French translations are defined in the translation file.

Steps to reproduce

  1. Render the form with {{ craft.formie.renderForm('donation') }}
  2. Add a validation error on the form (e.g., leave a required field empty)
  3. Observe if the error messages are displayed in French as per the formie.php translation file.

Form settings

  • Multi-page form: No
  • Submission Method: Ajax
  • Client-side Validation: Yes
  • Custom Form Templates: No

Craft CMS version

5.5.3

Plugin version

3.0.12

Multi-site?

No

Additional context

No response

@engram-design
Copy link
Member

What's your static translation string? Using the following is working for me:

'{attribute} cannot be blank.' => '{attribute} cannot be blank (in French).',

@romainpoirier
Copy link
Author

I was using a copy of one of the translation files (en/formie.php):

<?php

return [
  //
  // Email Messages
  //
  'formie_failed_notification_heading' => 'When an email notification fails to send:',
  'formie_failed_notification_subject' => 'Email notification failed to send for form "{{ form.title }}" on {{ siteName }}.',
  'formie_failed_notification_body' => "An email notification for the form “{{ form.title }}” has failed to send.\n\n" .
    "The error response was recorded: {{ emailResponse | json_encode }}.\n\n" .
    "To review it please log into your control panel.\n\n" .
    "{{ submission.cpEditUrl }}",

  '"{label}" should contain at most {max, number} {max, plural, one{character} other{characters}}.' => '"{label}" should contain at most {max, number} {max, plural, one{character} other{characters}}.',
  '(GDPR) {text}' => '(GDPR) {text}',
  ...
];

I assumed it included all the necessary translations for forms and planned to use it as a starting point. However, I noticed that the key {attribute} cannot be blank. is indeed not present in this file.

After adding it, I can confirm that this key is translated correctly.

Is there a registry of required translation keys? Or should I simply use another language file as a base (e.g., nl/formie.php)?

Thanks!

@engram-design
Copy link
Member

Apologies for that missing from the English file! We automate adding strings to that file, so I'll see if there's just been a mishap to including it. That should certainly be the central registry of translations strings to work from.

@engram-design
Copy link
Member

Yep, looks like a few were just plainly missed.

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