StoutLogic / acf-builder

An Advanced Custom Field Configuration Builder
GNU General Public License v2.0
792 stars 61 forks source link

Option page WPML translation #99

Open aitormendez opened 4 years ago

aitormendez commented 4 years ago

Hi, I'm tring to translate an options page created with acf-builder. Since there is no GUI in for this page in the "custom fields" tab, I can't set WPML up:

https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/#translate-option-pages

Is there a way to set to "translate" this option page using acf-builder? Thank you.

acf_add_options_page([
    'page_title' => get_bloginfo('name') . ' theme options',
    'menu_title' => 'ANV Options',
    'menu_slug'  => 'theme-options',
    'capability' => 'edit_theme_options',
    'position'   => '999',
    'autoload'   => true
]);

$options = new FieldsBuilder('theme_options');

$options
    ->setLocation('options_page', '==', 'theme-options');

$options
    ->addRepeater('background_image', [
        'label' => 'Background image',
    ])
    ->addImage('bg_img', [
        'label' => 'Image',
        'instructions' => 'Add background image',
        'return_format' => 'array',
        'preview_size' => 'thumbnail',
        'library' => 'all',
    ]);

return $options;
thomasjulienalain commented 4 years ago

Hey Aitor,

I was facing the same issue than you.

You probably already found a solution, but by checking at the ACF export file while using WPML's ACF glue plugin I found out than some new values where added.

It's working if you add this to your ACF Builder fields : "wpml_cf_preferences": 2,

1 = copy 2 = translate 3 = copy only once

mazero commented 4 years ago

Hey thomasjulienalain,

I see your answer on the issue to ACF Builder. Can you said me how u add WPML with ACF Builder ? "wpml_cf_preferiences => 2" is added to every field I add ? Thx

thomasjulienalain commented 4 years ago

Hello @mazero ,

I added manually those settings to each fields I need to copy or translate.

$template_about
    ->addAccordion('accordion_5', [
        'label' => 'Historique',
    ])

    ->addGroup('section_5', [
        'label' => 'Gérer les contenus',
    ])
    ->addText('title', [
        'label' => 'Titre',
        'required' => 1,
        'default_value' => 'Historique',
        'wpml_cf_preferences' => 2,
    ])
    ->addRepeater('list', [
        'label' => 'Historique',
        'layout' => 'row',
        'button_label' => '',
        'collapsed' => 'date',
        'wpml_cf_preferences' => 1,
    ])
        ->addText('date', [
            'label' => 'Année',
            'wrapper' => [ 'width' => '50%' ],
            'required' => 1,
            'wpml_cf_preferences' => 1,
        ])
        ->addTextarea('desc', [
            'label' => 'Description',
            'required' => 1,
            'wpml_cf_preferences' => 2,
        ])
    ->endRepeater()
    ->endGroup()
    ->addAccordion('accordion_5_end')->endpoint();
Jelmerkeij commented 1 year ago

I'm using it on options page for setting contact data like below, but the value for the field phone_number is not copied from the original (Dutch) language. Instead, the field stays empty in the other language.

Current WordPress and plugins:

Am I doing something wrong?

Setting up the fields on the options page like this:

$fields = new FieldsBuilder( 'Contactgegevens' );

$fields
    ->addTab( 'Contactgegevens' )
    ->addGroup( 'contact_data', [ 'label' => 'Contactgegevens' ] )
    ->addText( 'name', [ 'label' => 'Naam' ] )
    ->addText( 'address', [ 'label' => 'Adres' ] )
    ->addText( 'postal_code', [ 'label' => 'Postcode' ] )
    ->addText( 'city', [ 'label' => 'Plaats' ] )
    ->addEmail( 'email', [ 'label' => 'E-mailadres' ] )
    ->addText( 'phone_number', [ 'label' => 'Telefoonnummer', 'wpml_cf_preferences' => 3, ] ) // <-- SEE THE SETTING HERE
    ->addText( 'kvk_number', [ 'label' => 'KvK nummer' ] )
    ->addUrl( 'google_maps_url', [ 'label' => 'Google Maps URL', 'placeholder' => 'https://' ] )
    ->endGroup();

Edit: I should point out that wpml_cf_preferences = 1 does work and wpml_cf_preferences = 3 also works when not using grouped fields.