🌐 English | Español
English
This mu-plugin solves the issue where default Gravity Forms validation messages (like "This field is required.") fail to translate correctly on multilingual sites using WPML.
Context of the Problem
After updating to the latest versions of WPML, Gravity Forms, and Gravity Forms Multilingual (GFML), you might notice that default Gravity Forms validation messages remain in English across all secondary languages, even if the site is correctly configured with WPML.
The affected messages typically include:
• "This field is required."
• "There was a problem with your submission."
• "Please review the fields below."
• "Please enter a valid email address."
• "Invalid selection. Please select from the available choices."
• "Please enter a valid value."
• Other default validation messages.
Root Cause
Gravity Forms has two types of validation messages:
-
Custom field messages (errorMessage): These are manually configured by the administrator for each form field (the "Custom Validation Message" setting). GFML registers these as translatable strings in WPML String Translation, and they work perfectly.
-
Default messages: These are generated by Gravity Forms when there is no custom errorMessage, using __('This field is required.', 'gravityforms'). These do not pass through WPML or GFML — they rely on the standard WordPress translation system (.mo files).
The problem is threefold:
• WPML changes the language dynamically at runtime, but the Gravity Forms textdomain might be loaded in the incorrect language.
• There are no official Gravity Forms .mo files for several common locales (Czech, Greek, Romanian, Latin American Spanish variants, etc.).
• GFML only hooks into the gform_field_validation filter to translate custom errorMessages, not the default gettext-based messages.
Solution: A 3-Layer mu-plugin
This mu-plugin resolves the issue with a scalable approach that works for any current or future language, without requiring manual maintenance when adding new languages.
Layer 1 — Automatic Textdomain Reload
When switching languages with WPML (hook wpml_language_has_switched), the plugin:
-
Unloads the current Gravity Forms textdomain using unload_textdomain().
-
Resolves the correct locale using WPML's wpml_locale filter (works automatically for any configured language, without needing a manual dictionary).
-
Loads the corresponding .mo file from wp-content/languages/plugins/.
-
If the exact .mo file doesn't exist (e.g., es_CL), it tries the base locale of the language (e.g., es_ES).
Layer 2 — WPML String Translation Fallback
If Layer 1 fails to translate (no .mo file exists for that locale), the plugin hooks into the gettext filter and attempts to translate the string via WPML String Translation using apply_filters('wpml_translate_single_string', ...). This allows the administrator to manually translate the messages in WPML > String Translation > Context: gravityforms without touching any code.
Layer 3 — Hardcoded Emergency Translations
As a final safety net, the plugin includes direct translations of the most critical messages for ~30 languages. This only activates if Layers 1 and 2 fail.
Compatibility with Future Languages
Scenario Works Automatically? New language + Gravity Forms has a .mo file for it ✅ Yes (Layer 1) New language without .mo + admin translates in WPML ST ✅ Yes (Layer 2) New language without .mo + already in hardcoded fallback ✅ Yes (Layer 3) New language without .mo, not translated in WPML ST, and not in fallback ❌ Remains in English
You do not need to update the plugin when adding new languages, except in scenario 4. In that case, you can translate it in WPML String Translation (without touching code) or add it to the fallback array.
Installation
-
Download the amdt-gf-wpml-validation-fix.php file.
-
Upload it to the /wp-content/mu-plugins/ folder of your WordPress installation (if the mu-plugins folder doesn't exist, you must create it).
-
Ensure the permissions are correct: 644 for the file, 755 for the folder.
-
You do not need to activate anything — mu-plugins are loaded automatically.
-
You can verify its installation in Plugins > Must-Use in the WordPress admin dashboard.
Why a mu-plugin and not a normal plugin?
• It cannot be accidentally deactivated from the admin dashboard.
• It loads before normal plugins.
• It is more secure against compromised administrator accounts.
• It survives WordPress and other plugin updates.
Troubleshooting
The plugin doesn't appear in "Must-Use"
• Verify that the file is exactly at /wp-content/mu-plugins/amdt-gf-wpml-validation-fix.php (not inside a subfolder).
• WordPress only reads .php files directly in mu-plugins/, it does not scan subdirectories.
• Check permissions (644 file, 755 folder).
A message is still in English
Check if the specific message is included in the $emergency_fallback array in the code. If not, you have three options:
- Translate via WPML String Translation (no code changes needed):
• Go to WPML > String Translation.
• Search for the English text.
• If it doesn't appear, change the domain filter to gravityforms.
• Translate manually.
-
Add to the fallback array in the plugin with the necessary translations.
-
Set a custom errorMessage in the field editor — GFML translates this normally.
Conflicts with other plugins
The plugin adds filters with priority 20-25 specifically to run after GFML (priority 10). If you have custom code with a higher priority (e.g., 30+), it will overwrite the plugin's output.
License
This project is licensed under the terms of the GPL-2.0 or later license (WordPress compatible).
Credits
Originally developed by AMDT (Aún Más Difícil Todavía) to solve a client's issue with a multi-language form, and released to the WordPress community in the hope of saving hours of debugging for other developers encountering the same issue.
Español
Este mu-plugin soluciona el problema de los mensajes de validación por defecto de Gravity Forms (como "This field is required.") que no se traducen correctamente en sitios multilingües con WPML.
Contexto del problema
Tras actualizar a las últimas versiones de WPML, Gravity Forms y Gravity Forms Multilingual (GFML), es posible que los mensajes de validación por defecto de Gravity Forms sigan apareciendo en inglés en todos los idiomas secundarios, aunque el sitio esté correctamente configurado con WPML.
Los mensajes afectados suelen ser:
• "This field is required."
• "There was a problem with your submission."
• "Please review the fields below."
• "Please enter a valid email address."
• "Invalid selection. Please select from the available choices."
• "Please enter a valid value."
• Otros mensajes de validación por defecto.
Causa raíz
Gravity Forms tiene dos tipos de mensajes de validación:
-
Mensajes personalizados por campo (errorMessage): los que el administrador configura manualmente en cada campo del formulario (el ajuste "Custom Validation Message"). GFML los registra como cadenas traducibles en WPML String Translation y funcionan perfectamente.
-
Mensajes por defecto: los que Gravity Forms genera cuando no hay un errorMessage personalizado, usando __('This field is required.', 'gravityforms'). Estos no pasan por WPML ni por GFML — dependen del sistema estándar de traducción de WordPress (archivos .mo).
El problema es triple:
• WPML cambia el idioma dinámicamente en tiempo de ejecución, pero el textdomain de Gravity Forms puede estar cargado en el idioma incorrecto.
• No existen archivos .mo oficiales de Gravity Forms para varios locales comunes (checo, griego, rumano, variantes latinoamericanas de español, etc.).
• GFML solo engancha el filtro gform_field_validation para traducir errorMessages personalizados, no los mensajes por defecto basados en gettext.
Solución: mu-plugin con 3 capas de resolución
Este mu-plugin resuelve el problema con un enfoque escalable que funciona para cualquier idioma presente o futuro, sin necesidad de mantenimiento manual al añadir idiomas nuevos.
Capa 1 — Recarga automática de textdomain
Al cambiar de idioma con WPML (hook wpml_language_has_switched), el plugin:
-
Descarga el textdomain actual de Gravity Forms con unload_textdomain().
-
Resuelve el locale correcto usando el filtro wpml_locale de WPML (funciona automáticamente para cualquier idioma configurado, sin necesidad de un diccionario manual).
-
Carga el .mo correspondiente desde wp-content/languages/plugins/.
-
Si no existe el .mo exacto (ej. es_CL), prueba con el locale base del idioma (ej. es_ES).
Capa 2 — WPML String Translation como fallback
Si la capa 1 no logra traducir (no existe .mo para ese locale), el plugin engancha el filtro gettext e intenta traducir la cadena vía WPML String Translation con apply_filters('wpml_translate_single_string', ...). Esto permite que el administrador traduzca manualmente los mensajes en WPML > String Translation > Context: gravityforms sin tocar código.
Capa 3 — Traducciones hardcoded de emergencia
Como última red de seguridad, el plugin incluye traducciones directas de los mensajes más críticos para ~30 idiomas. Solo se activa si las capas 1 y 2 fallan.
Compatibilidad con idiomas futuros
Escenario ¿Funciona automático? Idioma nuevo + Gravity Forms tiene .mo para él ✅ Sí (Capa 1) Idioma nuevo sin .mo + admin traduce en WPML ST ✅ Sí (Capa 2) Idioma nuevo sin .mo + ya está en fallback hardcoded ✅ Sí (Capa 3) Idioma nuevo sin .mo, sin traducir en WPML ST, y no en fallback ❌ Se queda en inglés
No hay que actualizar el plugin al añadir idiomas nuevos, salvo en el escenario 4. En ese caso, se puede traducir en WPML String Translation (sin tocar código) o añadirlo al fallback.
Instalación
-
Descarga el archivo amdt-gf-wpml-validation-fix.php.
-
Súbelo a la carpeta /wp-content/mu-plugins/ de tu instalación de WordPress (si la carpeta mu-plugins no existe, debes crearla).
-
Asegúrate de que los permisos sean correctos: 644 para el archivo, 755 para la carpeta.
-
No hay que activar nada — los mu-plugins se cargan automáticamente.
-
Puedes verificar su instalación en Plugins > Imprescindibles del panel de administración de WordPress.
¿Por qué mu-plugin y no plugin normal?
• No se puede desactivar accidentalmente desde el panel de administración.
• Se carga antes que los plugins normales.
• Es más seguro frente a compromisos de cuentas de administrador.
• Sobrevive a actualizaciones de WordPress y otros plugins.
Troubleshooting
El plugin no aparece en "Imprescindibles"
• Verifica que el archivo está exactamente en /wp-content/mu-plugins/amdt-gf-wpml-validation-fix.php (no dentro de una subcarpeta).
• WordPress solo lee archivos .php directamente en mu-plugins/, no escanea subdirectories.
• Revisa los permisos (644 archivo, 755 carpeta).
Algún mensaje sigue en inglés
Comprueba si el mensaje concreto está incluido en el array $emergency_fallback del código. Si no, tienes tres opciones:
- Traducir vía WPML String Translation (sin cambios en código):
• Ve a WPML > String Translation.
• Busca el texto en inglés.
• Si no aparece, cambia el filtro de dominio a gravityforms.
• Traduce manualmente.
-
Añadir al fallback del plugin con las traducciones necesarias.
-
Poner un errorMessage personalizado en el editor del campo — este sí lo traduce GFML normalmente.
Conflictos con otros plugins
El plugin añade filtros con prioridad 20-25 específicamente para ejecutarse después de GFML (prioridad 10). Si tienes código personalizado con prioridad mayor (ej. 30+), sobrescribirá la salida del plugin.
Licencia
Este proyecto está licenciado bajo los términos de la licencia GPL-2.0 o posterior (compatible con WordPress).
Créditos
Desarrollado originalmente por AMDT (Aún Más Difícil Todavía) para resolver un problema de un cliente con un formulario multi-idioma, y liberado para la comunidad de WordPress con la esperanza de ahorrar horas de depuración a otros desarrolladores que se encuentren con el mismo problema.