Custom Fields
Support MB Settings Page Best way to translate options page Reply To: Best way to translate options page


Anh Tran

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 );