Open Triloworld opened 7 years ago
New language can be added : #16
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!
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 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.
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.
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.