最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

translation - Translating form labels shortcode output

programmeradmin2浏览0评论

I'm using MyMail plugin to manage my newsletter.
I'm also using WPML to manage translations, there is no compatibility between the two plugins.
The subscription form, is placed in the footer area, through a MyMail shortcode and the wordpress text widget.

I want to translate the field labels, to the active language: So I was thinking on writing a filter for the "widget_text", search the "label name" and preg_replace() its output... But I don't find the way to achieve it.

Looking in the php class that manage the form, I could see that the function that outputs the form, stores the final code as:

return apply_filters('mymail_form', $html, $formid, $form);

So I guess that I need "search and replace" in the $html variable.

Any ideas? Many thanks!

I'm using MyMail plugin to manage my newsletter.
I'm also using WPML to manage translations, there is no compatibility between the two plugins.
The subscription form, is placed in the footer area, through a MyMail shortcode and the wordpress text widget.

I want to translate the field labels, to the active language: So I was thinking on writing a filter for the "widget_text", search the "label name" and preg_replace() its output... But I don't find the way to achieve it.

Looking in the php class that manage the form, I could see that the function that outputs the form, stores the final code as:

return apply_filters('mymail_form', $html, $formid, $form);

So I guess that I need "search and replace" in the $html variable.

Any ideas? Many thanks!

Share Improve this question asked Dec 1, 2013 at 15:39 CapiedgeCapiedge 7881 gold badge7 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If anyone is looking for a solution, here is a way (probably not the better one) to achieve it:

add_filter('widget_text', 'filtering_form_labels');
function filtering_form_labels($html) {

    if ( ICL_LANGUAGE_CODE=='en' ) {/*ICL_LANGUAGE_CODE used in WPML to know the active language*/
        $esp = array('Nombre', 'Apellidos', 'Suscribirse'); /*Array with words to be replaced*/
        $eng = array('First Name', 'Last Name', 'Subscribe'); /*Array with new words*/
        ob_start();
        $html = str_replace($esp, $eng, $html);
        ob_end_clean();
    }

    return $html;
}
发布评论

评论列表(0)

  1. 暂无评论