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 3 replies, has 2 voices.

Last updated by igorN-6 5 months ago.

Assigned support staff: Raja Mohammed.

Author Posts
May 17, 2019 at 11:08 am #3833765

igorN-6

Tell us what you are trying to do?
Translate the fields from a file located at /wp-content/plugins/theme-my-login-custom.php

with the respective content:
function add_tml_registration_form_fields() {
tml_add_form_field( 'register', 'first_name', array(
'type' => 'text',
'label' => 'First Name',
'value' => tml_get_request_value( 'first_name', 'post' ),
'id' => 'first_name',
'priority' => 15,
) );
tml_add_form_field( 'register', 'last_name', array(
'type' => 'text',
'label' => 'Last Name',
'value' => tml_get_request_value( 'last_name', 'post' ),
'id' => 'last_name',
'priority' => 15,
) );
tml_add_form_field( 'register', 'company', array(
'type' => 'text',
'label' => 'Company',
'value' => tml_get_request_value( 'company', 'post' ),
'id' => 'company',
'priority' => 15,
) );
}

That adds 3 extra fields to the registration form.

Is there any documentation that you are following?
hidden link
And then tried a couple of threads on this forum, but they weren't really the same thing.

Is there a similar example that we can see?
Maybe this: https://wpml.org/forums/topic/translate-custom-text-in-php-file/

What is the link to your site?
bezares.com

May 17, 2019 at 11:13 am #3833789

igorN-6

2 things that can be useful:

1 - Notice the file needs to be at the top /plugin page, not inside a folder as usual, not sure how this affect WPML
2 - WordPress, Woocommerce and Theme My Login all have the same field already translated (check images), would be better to be able to use these translations instead of creating yet another new string.

May 17, 2019 at 12:13 pm #3834295

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi,

I think you are trying to translate the custom field label correct me if I'm wrong. For that, the label value needs to be wrapped in a get_text() function. Your updated code will be like


function add_tml_registration_form_fields() {
tml_add_form_field( 'register', 'first_name', array(
'type' => 'text',
'label' => __('First Name','custom_login_field'),
'value' => tml_get_request_value( 'first_name', 'post' ),
'id' => 'first_name',
'priority' => 15,
) );
tml_add_form_field( 'register', 'last_name', array(
'type' => 'text',
'label' => __('Last Name','custom_login_field'),
'value' => tml_get_request_value( 'last_name', 'post' ),
'id' => 'last_name',
'priority' => 15,
) );
tml_add_form_field( 'register', 'company', array(
'type' => 'text',
'label' => __('Company','custom_login_field'),
'value' => tml_get_request_value( 'company', 'post' ),
'id' => 'company',
'priority' => 15,
) );
}

Once updated. goto WPML > Theme and plugin localization > Plugin localization, select your plugin and click on the button 'Scan selected plugin for strings' .

After the process is finished the custom field label will be available for translation from String translation under the domain 'custom_login_field'.

I hope this helps you better, Let me know the results.

Kind regards
Raja

May 17, 2019 at 12:24 pm #3834379

igorN-6

I replaced the code and it still couldn't find the strings...

So I made a copy of that php file inside the plugin folder (it needs to be places on the /plugin/ folder) and then it detected the new strings.

Translated them, cleared cache and it worked perfectly.

Many thanks for the quick solution.