Custom Fields
Re-Envisioned
Support MB Settings Page Best way to translate options page

  • Creator
    Topic
  • #11004
    Resolved Bezzo
    Participant

    Hello,

    I’m not sure if it is a good place to ask. I’m using WPML and I’m wondering if there’s an option to translate custom setting page like normal page. I’ve create custom plugin which includes metabox via composer. Also I’ve created wpml-config.xml file and fields I’ve registered ale capable of translation but not in user friendly way.

    These fields can be translated via “String translation” menu page in WPML. Moreover there’s raw HTML in these fields which is generated form WYSIWYG field so “regular” user can be confused. I would like to achieve something like normal page

    I’m not sure if it is possible or just I don’t know how to do that.

    I know that ACF PRO allow you to “separate” custom fields in settings page depended on language.

    Right now with metabox if I switch languages in my settings page content of fields is the same and changing it changes fields globally.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #11019
    Anh Tran
    Keymaster

    Hi Bezzo,

    Interesting question! Thanks for asking this.

    Using wpml-config.xml is the standard way and is recommended by WPML. However, if you need to have different settings per language, you can use the ICL_LANGUAGE_CODE constant to detect current language and set the field IDs based on that.

    This is the sample code:

    $prefix = ICL_LANGUAGE_CODE . '_';
    $meta_boxes[] = [
        'title' => 'Fields',
        'fields' => [
            [
                'id' => $prefix . 'text',
                'name' => 'Text',
                'type' => 'text',
            ],
            // Other fields.
        ],
    ];

    To get the field value, you can create a helper function like this:

    function my_setting( $field_id ) {
        $option_name = 'my_option';
    
        $field_id = ICL_LANGUAGE_CODE . '_' . $field_id; // Prepend the language code.
        return rwmb_meta( $field_id, array( 'object_type' => 'setting' ), $option_name );
    }
    #12581
    anja
    Participant

    I also have an extra settings page and WPML in use.
    I created it with the Page Builder.
    How can I translate the fields now?

    Settings page
    https://abload.de/img/bildschirmfoto2018-12qxfh0.png

    Code in the template
    https://abload.de/img/bildschirmfoto2018-12w3fdw.png

    Result on the front page
    https://abload.de/img/bildschirmfoto2018-1277etz.png

    #12619
    Anh Tran
    Keymaster

    Hi anja,

    Please follow the instruction in the previous reply and the WPML documentation.

    #12628
    anja
    Participant

    And how can I use “$prefix” in the “Meta Box Builder” plugin?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Newsletter

Subscribe to our newsletter to receive news and tutorials for Meta Box and WordPress.


grid gear info copy caret-up caret-down trash