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 3.49 hours from now. Thank you for your understanding.

This topic contains 16 replies, has 3 voices.

Last updated by Nigel 6 months, 3 weeks ago.

Assisted by: Nigel.

Author Posts
February 26, 2024 at 5:25 pm #15345657

Nigel
Supporter

Timezone: Europe/Madrid (GMT+02:00)

Sorry about this, I wasn't able to pinpoint the source of the problem on your site, so I took a copy of the theme and the Machic core plugin to test on my own local site, where the link is also proving difficult to translate.

Let me speak to my colleagues and see if I can get some specific direction.

I'll get back to you.

February 28, 2024 at 4:40 pm #15355073

Nigel
Supporter

Timezone: Europe/Madrid (GMT+02:00)

I'm pleased to say we have a solution. We have identified problems handling link translation for Elementor custom widgets which have repeating elements (in this case the slider).

Although we should in future be able to handle it with conventional custom XML (such as that which I already provided to you), in this case we need to add some code to your child theme's functions.php.

First, you need to go to WPML > Settings > Custom XML Configuration and remove just the part of the custom XML which registers the machic home slider widget, i.e. this part:

    <widget name="machic-home-slider">
      <fields>
        <field>auto_speed</field>
        <field>arrows</field>
        <field>slider_items</field>
      </fields>
      <fields-in-item items_of="slider_items">
        <field>slider_image>url</field>
        <field>slider_title</field>
        <field>slider_subtitle</field>
        <field>slider_second_subtitle</field>
        <field>slider_offer</field>
        <field>slider_btn_title</field>
        <field>slider_btn_link>url</field>
      </fields-in-item>
    </widget>

You can leave the other widget declarations in place.

Then add this code to your functions.php:

/**
 * Custom registration of machic home slider widget for translation
 */

 add_action('init', function () {
	add_filter('wpml_elementor_widgets_to_translate', function ($widgets) {
		$widgets['machic-home-slider'] = [
			'conditions' => ['widgetType' => 'machic-home-slider'],
			'fields'     => [],
			'integration-class' => 'machicHomeSlider'
		];
		return $widgets;
	});

	/**
	 * Class to translate the Machic machic-home-slider widget.
	 * 
	 * @see wpmltriage-1291
	 */
	class machicHomeSlider extends WPML_Elementor_Module_With_Items {

		/**
		 * @return string
		 */
		public function get_items_field() {
			return 'slider_items';
		}

		/**
		 * @return array
		 */
		public function get_fields() {
			return [
				'slider_title',
				'slider_subtitle',
				'slider_second_subtitle',
				'slider_offer',
				'slider_btn_title',
				'slider_btn_link' => [
					'url'
				]
			];
		}

		/**
		 * @param string $field
		 *
		 * @return string
		 */
		protected function get_title($field) {
			switch ($field) {
				case 'slider_title':
					return esc_html__('Slider Title', 'machic');
				case 'slider_subtitle':
					return esc_html__('Slider Subtitle', 'machic');
				case 'slider_second_subtitle':
					return esc_html__('Slider Second Subtitle', 'machic');
				case 'slider_offer':
					return esc_html__('Slider Offer', 'machic');
				case 'slider_btn_title':
					return esc_html__('Slider Button Title', 'machic');
				case 'url':
					return esc_html__('Slider Button: Link', 'machic');
				default:
					return '';
			}
		}

		/**
		 * @param string $field
		 *
		 * @return string
		 */
		protected function get_editor_type($field) {
			switch ($field) {
				case 'slider_title':
					return 'LINE';
				case 'slider_subtitle':
					return 'LINE';
				case 'slider_second_subtitle':
					return 'LINE';
				case 'slider_offer':
					return 'LINE';
				case 'slider_btn_title':
					return 'LINE';
				case 'url':
					return 'LINK';
				default:
					return '';
			}
		}
	}
});

You then need to make a trivial edit to the page, update it, and then translate it again.

You won't see internal links in the translation editor, as they are handled automatically, but if you have any external links you can search for them by searching for "http".

Let me know how you get on.

March 1, 2024 at 12:45 pm #15363019

georgiosS-18

The latest addition has resolved this issue.

Thank you.

georgiosS-18 confirmed that the issue was resolved on 2024-03-01 12:45:39.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.