Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by marcoR-2 1 year, 7 months ago.

Assisted by: Nicolas V..

Author Posts
September 21, 2023 at 5:14 am #14434483

marcoR-2

I've registered few strings for show translated content in the backend.
There is one that is registered in the same way then the others, but is not showing translated

Here part of the code:
'fields' => [
[
'name' => __( 'Location Name', 'sl-event' ),
'id' => $prefix . 'location_name',
'type' => 'text',
'std' => __('Main location', 'sl-event' ),
],
[
'name' => __( 'Address', 'sl-event' ),
'id' => $prefix . 'address',
'type' => 'text',
],
[
'name' => __( 'Position', 'sl-event' ),
'id' => $prefix . 'position',
'type' => 'osm',
'std' => '41.78632956023742, 1.0946043600846636',
'address_field' => 'address',
],
],
'tab' => 'tab_basic_data',
],

All are working minus "Main Location"

Any help to make it work, please?

September 21, 2023 at 4:36 pm #14441109

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hello,

Welcome to the WPML support forum. I think that you can't use __() function for the default value 'std' because it's not a label.

- You should use 'std' => 'Main location',.
- And for the first page (or post) saved with that default value, you will be able to translate the value while translating the page.

Here is an example generated with hidden link:

<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );

function your_prefix_register_meta_boxes( $meta_boxes ) {
    $prefix = '';

    $meta_boxes[] = [
        'title'   => esc_html__( 'Untitled Field Group', 'online-generator' ),
        'id'      => 'untitled',
        'context' => 'normal',
        'fields'  => [
            [
                'type'        => 'text',
                'name'        => esc_html__( 'Location Name', 'online-generator' ),
                'id'          => $prefix . 'location_name',
                'desc'        => esc_html__( 'Description', 'online-generator' ),
                'std'         => 'Default value',
                'placeholder' => esc_html__( 'Main location', 'online-generator' ),
            ],
        ],
    ];

    return $meta_boxes;
}

PS: Note the use of esc_html__() which will escape the text for safe use instead of __().

September 22, 2023 at 6:30 am #14443493

marcoR-2

Hi.
This is content for the backend.
But cheking your code a realize that the problem was thatI was cheking with an ancient post.

At the end, __() is working propertlly with 'std'

Thank You