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.

Our next available supporter will start replying to tickets in about 6.71 hours from now. Thank you for your understanding.

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Ahmed Mohammed 1 year ago.

Assisted by: Ahmed Mohammed.

Author Posts
May 15, 2023 at 2:22 pm #13648781

marcoR-2

Hi!

I have created a few custom fields associated to a page.
This custom fields are stored in a custom table.

In WPML -> settings -> custom fields translation are not showing.

How can I make it work?

Thank You

May 15, 2023 at 6:27 pm #13650707

Ahmed Mohammed
Supporter

Timezone: Africa/Cairo (GMT+03:00)

Hi there,

Thank you for contacting WPML support. While you are waiting for one of my colleagues to take this ticket and work on it, let me provide you with the first debugging steps or if I can help with the issue quickly.

WPML → Settings → Custom Fields translation will show the custom fields stored in the wp_postmeta table.

To translate the data added to custom tables, then you will need to use WPML hooks to translate them.
Here is the list of hooks: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

I would suggest you take a look at these 4 hooks first to see if it helps:
- https://wpml.org/wpml-hook/wpml_register_single_string/
- https://wpml.org/wpml-hook/wpml_translate_single_string/
- https://wpml.org/wpml-hook/wpml_register_string/
- https://wpml.org/wpml-hook/wpml_translate_string/

Using the above hook you can register the strings for translations and translate them from WPML->String Translations and use another hook to display it on the front end.

Also, to know more about WPML tables, please check this documentation https://wpml.org/documentation/support/wpml-tables/

Let me know if this helps.

May 16, 2023 at 8:07 am #13653025

marcoR-2

Hi!

Thank you for your answer.

I end up with this code, but I still not see anything.

<?php

function register_custom_field_for_translation() {
global $wpdb;
$table_name = $wpdb->prefix . 'sl_admin';
$field_name = 'sl_admin_text';
do_action('wpml_register_single_string', 'sl_texts', 'Custom', $table_name . ':' . $field_name, $field_name);
}
add_action('wpml_register_string', 'register_custom_field_for_translation');

function translate_custom_field($value, $original_value, $context, $language_code) {
global $wpdb;
$table_name = $wpdb->prefix . 'sl_admin';
$field_name = 'sl_admin_text';
if ($context === 'Custom' && $original_value === $table_name . ':' . $field_name) {
$translated_value = apply_filters('wpml_translate_single_string', $value, 'sl_texts', 'Custom', $table_name . ':' . $field_name, $language_code);
return $translated_value;
}

return $value;
}
add_filter('icl_translate', 'translate_custom_field', 10, 4);

May 16, 2023 at 6:08 pm #13659029

Ahmed Mohammed
Supporter

Timezone: Africa/Cairo (GMT+03:00)

Hi Marco,

In WPML support, we're not developers; unfortunately, we cannot help with custom coding.

With that said, I can see that you're trying to register a string package. We have a detailed example here: https://wpml.org/documentation/support/string-package-translation/.

Please give it a try and let us know how it goes.

Regards,

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.