Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPML translation of the Controls_Manager::URL not working as expected in our custom widget. #6786

Closed
ryanlabelle opened this issue Jan 18, 2019 · 10 comments

Comments

@ryanlabelle
Copy link

ryanlabelle commented Jan 18, 2019

Prerequisites

  • [X ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • [ X] The issue still exists against the latest stable version of Elementor.

Description

We've followed the guide over here provided by WPML to translate our custom Elementor widget:

https://wpml.org/documentation/plugins-compatibility/elementor/how-to-add-wpml-support-to-custom-elementor-widgets/

It's working for most fields but the Controls_Manager::URL is an array with ['URL'], and ['is_external'] and that does not seem to be coming through in the Translation Editor.

The bundled Elementor button widget also uses the Controls_Manager::URL is coming through just fine in the translation editor, so it's something related to our custom widgets.

Here is the code sample from the WPML site for translating Elementor widgets.

  $widgets[ $this->get_name() ] = [
     'conditions' => [ 'widgetType' => $this->get_name() ],
     'fields'     => [
        [
           'field'       => 'title',
           'type'        => __( 'Hello World Title', 'hello-world' ),
           'editor_type' => 'LINE'
        ],
     ],
  ];
 
  return $widgets;
}

That's great for a simple text field, how would one translate a field that uses the Controls_Manager::URL?

I'm also reaching out to the WPML team. I'll post any solutions that they provide here. 👍

@bainternet
Copy link
Contributor

@ryanlabelle

thanks for reporting, sadly, we have no control over how WMPL handles translation of any control.

thanks.

@synio-wesley
Copy link

I have the same issue. Did you figure anything out, @ryanlabelle

@synio-wesley
Copy link

Ok I figured it out. Try this:

'fields' => [
    'your_field_name' => [
        'field' => 'url',
        'type' => __('Field description', 'example-translation'),
        'editor_type' => 'LINE'
    ],
],

The important thing here is to use a key for the array, and this key should be equal to your field name. And then you should use 'url' for the field key in the array...

For editor_type you can also use LINK if you want, but I use LINE because otherwise relative links like '/something/' will not display in the WPML edit screen.

@ryanlabelle
Copy link
Author

Thanks @synio-wesley ! I'll give that a try. :)

@ryanlabelle
Copy link
Author

ryanlabelle commented Feb 8, 2019

@synio-wesley Thanks again for your help. It's working, with on caveat, when I have two url controls in the same widget, WPML will only recognizes one of them. Any ideas?

'fields'     => [
    [
        'field'       => 'button_1_text',
        'type'        => __( 'Button Text', 'th-widget-pack' ),
        'editor_type' => 'LINE'
    ],
    'button_1_link' => [
        'field' => 'url',
        'type' => __('Button Link', 'th-widget-pack'),
        'editor_type' => 'LINE'
    ],
    [
        'field'       => 'button_2_text',
        'type'        => __( 'Button Text', 'th-widget-pack' ),
        'editor_type' => 'LINE'
    ],
    'button_2_link' => [
        'field' => 'url',
        'type' => __('Button Link', 'th-widget-pack'),
        'editor_type' => 'LINE'
    ],
],

Displays the following in the WPML editor:

https://cl.ly/f2e2057c169e

No issue if I have a single URL in the widget, but more than 1 and it's getting lost.

@ryanlabelle
Copy link
Author

I'll be reaching out to WPML as well.

@synio-wesley
Copy link

@ryanlabelle I have checked out this issue in detail for you, and I think I have found a bug in the WPML Elementor integration code. I have also written a fix for the problem. I will open a ticket on the wpml-page-builders-elementor GitHub that I found and hopefully they can fix it that way :-)

@synio-wesley
Copy link

@ryanlabelle As you can see, I have created a ticket so this issue can hopefully be fixed in a next version :-)

In the meantime, you can probably work around the issue by writing a custom integration-class and re-implementing get() and update() so it handles this correctly... (not the easiest workaround...)

@ryanlabelle
Copy link
Author

@synio-wesley you rock! Thank you so much. It looks like they already responded. I hope that you have a great weekend. Cheers.

@synio-wesley
Copy link

@ryanlabelle Could you check out OnTheGoSystems/wpml-page-builders-elementor#65 and give the people over there a complete example that they can use for their tests? I don't really have the time to focus on a backwards-compatible fix right now, so I'm hoping they will be able to fix it once they have a complete example. (Otherwise, I might take a look again for another pull request taking backwards compatibility into account after my holidays in a few weeks.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants