-
Notifications
You must be signed in to change notification settings - Fork 136
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
base: master
Are you sure you want to change the base?
Conversation
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); |
There was a problem hiding this comment.
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
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? |
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; | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@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. |
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. |
@aufmkolk Your changes work like a charm! |
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.