I got two problems.

Problem 1:

  1. I have translated mailchimp's pot file into two languages. The .mo has been tested to be working.
  2. But WP fails to show the ajax returns for other languages for the mailchimp form and/or widget for mailchimp list subscribe form.

I got around this by modifying the mailchimp.php like following:

    $textdomain = 'mailchimp_i18n'; #line 57 to start
    if (defined('WPLANG'))
        $lang=WPLANG;
    $locale = apply_filters( 'plugin_locale', $lang, $textdomain);

How did I figure out? In place of this $lang variable, default mailchimp.php has get_locale() defined in l10n.php of wp-includes.

When I placed a print_r($locale) before modifying as above. It shows the correct language set at wp-config's WPLANG. But when the mailchimp form is submitted it gets just default en_US!

*Where does it get the en_US, when I haven't set it?* I found it very weird, line 48-49 of l10n.php for definition of get_locale() contains:

    if ( empty( $locale ) )
    $locale = 'en_US';

Which, I think gets $locale as empty while in my case was called from the form. Which is very unlikely! But it happens in four instances of my testing.

What my modification at mailchimp.php gets me to? I can now get the other language (ie Arabic) strings to my mailchimp form responses. But as its detected from WPLANG, I cannot switch to English in site's English mode.

Problem 2: To switch languages on the fly. I used qtrans_getLanguage() in place of get_locale() in the mailchimp.php's code part. Thus, it becomes:

$locale = apply_filters( 'plugin_locale', qtrans_getLanguage(), $textdomain);

If I print_r($locale) after this line. It shows current language. But not when the form is submitted. The form's response always shows it as (en)!.

Now, problem1 is very unlikely to happen and is unusual. But for problem2 I definitely think there is a smart work around. Why would the qTranslate report wrong while called from the Ajax of that form?

Also, I do not want to modify core plugin files. Currently, I had to modify mailchimp.js to manually match and replace common strings(And I hate it!).

有帮助吗?

解决方案

Solved it by following this and this

But as mailchip.js has this 'ajax_url' I searched in the mailchimp plugin where this URL is generated from. Its generated at line number 96 in mailchimp.php

    'ajax_url' => trailingslashit(home_url().'/'.  qtrans_getLanguage()),

I just added the '/'. qtrans_getLanguage() part.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top