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

Update jquery.ajaxchimp.js to add support for error messages containing custom information #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

afmklk
Copy link

@afmklk afmklk commented Jan 14, 2015

I have rewritten the "translate and display message part" so that responses don't have to be an EXACT copy of Mailchimp's error message. Some error messages contain custom information (username, email, list name etc.) and would not be translated without this fix.

I have rewritten the "translate and display message part" so that responses don't have to be an EXACT copy of Mailchimp's error message. Some error messages contain custom information (username, email, list name etc.) and would not be translated without this fix.
) {
msg = $.ajaxChimp.translations[settings.language][$.ajaxChimp.responses[msg]];
msg = $.ajaxChimp.translations[settings.language][msgnr];
}
label.html(msg);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add msg variable to the settings.callback(resp, msg); so It will be possible to make use of this messages.
BTW I look forward to merge it to master branch

@afmklk
Copy link
Author

afmklk commented Jan 19, 2015

Good Point @dobiatowski

On a related note: It seems like Mailchimp's API response now includes translated error messages itself so this function may not be necessary any longer. Tested with German, can someone confirm this for other languages?

@adamlukaszczyk
Copy link

I confirm - messages are translated but only successful ones. Error messages I get still in English.

@rik84 can you paste your request URL ? Maybe I am missing something.

if (msg.indexOf($.ajaxChimp.responses[length])!==-1) {
msgnr = length;
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a similar fix for this locally, but I didn't change the responses structure.
My fix looks like:

var i18n = $.ajaxChimp.translations;
// Translate and display message
if (settings.language !== 'en' && i18n && i18n[settings.language]) {
    var translation = i18n[settings.language][$.ajaxChimp.responses[msg]];
    if (!translation) {
        // try partial match
        $.each($.ajaxChimp.responses, function(resp, key) {
            if (msg.indexOf(resp) > -1) {
                translation = i18n[settings.language][key];
                return;
            }
        });
    }
    if (translation) {
        msg = translation;
    }
}

This way we only do partial matches if the string doesn't exist in the hash map.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think the fix needs to be a lot better. Meaning, there are cases where the response is like:

{"result":"error","msg":"[email protected] is already subscribed to list My Newsletter. <a href=\"http:\/\/address.list-manage1.com\/subscribe\/send-email?u=uuu&id=ddd&e=xxx==\">Click here to update your profile.<\/a>"})

I believe the best fix would be not to do partial matches (like I did also) but rather regular expressions to extract the information we need.

BTW, any luck on requesting Mailchimp to return these errors already translated from the server? Basically the translations exist and can be tweaked from the Mailchimp webpage. I still don't understand why they don't translate this before sending the response. Perhaps we could send a language param to get the response from them directly?

The reason why I'm saying this is because I might have customers that want to translate the same errors in different ways and that way I wouldn't have to change the translations per customer, and rather just tell them how to do on Mailchimp interface.

@adamlukaszczyk
Copy link

@alias-mac Non error messages are translated by MailChimp. You can set specific language for every list in MailChimp admin. Only errors messages which starts from "0 - " are generic.

This is what MailChimp should fix on their side - but this is a wish only :D

Translations mapping based on content of messages is not very reliable so in my case I do email validation on my side and only check if response has "0 - " error.

@scdoshi
Copy link
Owner

scdoshi commented Nov 26, 2015

I have a fix for this using regex matches in the dev-2.0 branch, but it comes with some other changes too, so you would might have to change your code a bit. Let me know if you try it out.

@ITFactoryAUT
Copy link

@aufmkolk Your changes work like a charm!
Now the translation works great, but you need to add "6: 'The username portion of the email address is empty'," this to the response list and translation in case when the user types only a single @ as email-address!

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

Successfully merging this pull request may close these issues.

5 participants