ACF choices to register in WPML

Viewed 151

As WPML does not provide a solution to translate [choices] fields I would like to add a custom function to register it within WPML, however I am not a star in php, but I have below but it doesn't register it in WPML String Translation:

$field = get_field_object( 'type_of_property' ); // acf field with choices
if (!empty($field['choices'])) {
    foreach( $field['choices'] as $choice ){
        do_action( 'wpml_register_single_string', 'ACF Domain', 'name'.$choice , $choice );
        $acflabel= apply_filters( 'wpml_translate_single_string', $choice, 'ACF Domain', 'name'.$choice, NULL );
        echo ' - ' . $acflabel;
    }
}

Is above method going into the right direction or do I need to call all the choices within the type_of_property field?

1 Answers

I believe you should be able to do this:

$field = get_field_object( 'type_of_property' );
if ( !empty( $field['choices'] ) ) {
    foreach( $field['choices'] as $choice ){
        echo ' - ' . __( $choice, 'ACF Domain' );
    }
}

Then scan your theme/plugin for strings:

  1. In admin dashboard go to WPML > Theme and Plugins Localization
  2. Select the theme or plugin and click to scan it.
  3. After the scan is done, you should be able to find the strings on the String Translation page.

Doc:

https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/#:~:text=To%20scan%20for%20hard%2Dcoded%20strings%3A

Related