advanced-forms icon indicating copy to clipboard operation
advanced-forms copied to clipboard

Request: Multilanguage support

Open Triloworld opened this issue 8 years ago • 5 comments

There is some field that don't work in multilanguage space. For example: description, Success message, email form ... Can be possible to just create another one entry for another language?

I use Polylang, don't know if it work on WPML. No information about it.

Triloworld avatar Aug 25 '17 13:08 Triloworld

New language can be added : #16

Triloworld avatar Aug 27 '17 09:08 Triloworld

I haven't tried it out with either WPML or Polylang so I'm not sure how to make it work currently.

I'm a bit busy at the moment but will try it out with Polylang when I find the time!

fabianlindfors avatar Sep 26 '17 12:09 fabianlindfors

Turns out multilingual support is quite easy to achieve with polylang-pro, using the following:

add_filter( 'pll_get_post_types', 'mytheme_pll_get_post_types', 10, 2 );
function mytheme_pll_get_post_types( $post_types, $is_settings ) {
	$post_types['af_form'] = 'af_form';

	return $post_types;
}

The form keeps the same key when translated (but not the same ID) and when embedded on a page it displays in the proper language! Creating posts in the corresponding language also works OOTB.

lewebsimple avatar Jul 16 '18 18:07 lewebsimple

@lewebsimple Thanks! How did you translate the form fields? Or did you?

Another code added this to the same filter: ''$post_types[] = 'acf-field-group';''

Which makes all acf fieldsets translatable, but I'm kind of anxious with that since I don't want to maintain all language versions of all fieldsets when I only need the forms fields translated.

Jaska avatar Sep 12 '18 13:09 Jaska

Yeah, maintaining translations for your field groups can be a PITA, plus you might have problems with differing group keys and what not.

I prefer translating only the form fields by setting the proper textdomain in acf/settings/l10n_textdomain, then making sure the theme's translations include the various field strings (labels, instructions). These can be tweaked with the acf/translate_field hooks for date format, number prefix/suffix, etc. Also, I use a save_post hook on acf-field-group post type to automatically export all translation strings to acf-json/acf-translations.php, which doesn't need to be included but is still picked up by loco-translate. This last bit is tricky because you have to handle special field types like groups, repeaters and others recursively.

As far as localizing AF forms go, the solution I posted above isn't perfect yet, so for now I'm sticking with multiple forms sharing the localized field group.

lewebsimple avatar Sep 12 '18 13:09 lewebsimple