Small update for interested readers:
As some of our sites have various editors and we can not switch language of whole WordPress admin every time somebody adds a new form in some language, we are currently using a workaround for WPML.
It replaces the “Add new” button with a list of buttons for each registered WPML language and passes the language as undocumented param locale="xx_XX"
to CF7 form creation, screenshot.
With this workaround the form success/error messages and locale settings are set up in correct language.
Notes:
1. WPML has to be configured to NOT translate CF7 posts (default).
2. “Add new” item in side menu is NOT affected/replaced.
3. If you edit/copy a form, it keeps the language of creation.
4. Tested with WordPress 4.5.2, WPML 3.3.8, CF7 4.4.2
5. Add code to functions.php of (child-)theme.
// WPML with CF7, hack to create forms with correct locale param
function wpml_cf7_admin_footer() {
$languages = apply_filters( 'wpml_active_languages', NULL, 'skip_missing=0' );
if ( !empty( $languages ) ) {
$languages = json_encode( $languages );
?>
<script type="text/javascript">
var wpml_cf7 = <?php echo $languages; ?>;
var wpml_cf7_btn = jQuery('h1 a[href$="admin.php?page=wpcf7-new"]');
var wpml_cf7_href = jQuery(wpml_cf7_btn).attr('href');
var wpml_cf7_new = jQuery('<span/>');
if (wpml_cf7_btn && wpml_cf7_href) {
jQuery.each(wpml_cf7, function(key, obj) {
if (wpml_cf7[key].default_locale) {
jQuery(wpml_cf7_new).append(
jQuery(wpml_cf7_btn).clone()
.attr('href', wpml_cf7_href + '&locale=' + wpml_cf7[key].default_locale)
.attr('title', wpml_cf7[key].translated_name)
.append(
jQuery('<img/>')
.attr('src', wpml_cf7[key].country_flag_url)
.css('margin-left', '4px')
)
);
}
});
jQuery(wpml_cf7_btn).replaceWith(wpml_cf7_new);
}
</script>
<?php
}
}
add_action( 'admin_footer-toplevel_page_wpcf7', 'wpml_cf7_admin_footer' );
Maybe it helps somebody, feedback welcome…