views:

88

answers:

2

Hi, I use this plugin: jQuery.i18n.properties

I put this code:

/* Do stuff when the DOM is ready */
    jQuery(document).ready(loadMessage);

    /*
     * Add elements behaviours.
     */
    function loadMessage() {
        jQuery("#customMessage").html("test");
        jQuery.i18n.properties({
            name:'up_mail_messages',
            path:'https://static.unifiedpost.com/apps/myup/customer/upmail/upmail_messages/',
            mode:'both',
            language:'en',
            callback: function() {
                var messageKey = 'up.mail.test';
                //alert(eval(messageKey));
                jQuery('#customMessage').html(jQuery.i18n.prop(messageKey));
            }
        });
    }

I do not understand why, in the customeMessage div it prints out:

[up.mail.test]

instead of the value of it:

up.mail.test=messages loaded from en

Can anybody show me where i am wrong? I;ve spent about two hours on it without finding any clue...

Many Thanks.

Ps: here is the message file: https://static.unifiedpost.com/apps/myup/customer/upmail/upmail_messages/up_mail_messages_en.properties

EDIT: After testing locally, all works good. But if the messages files are located to another host (like in the above example) it seems that it fails...It would be nice if anyone can confirm this...

EDIT 1: It does not work because inside the js script there is an ajax call to read the messages files. Well, as you probably know, Cross-Domain XMLHttpRequest Calls are forbidden in ajax due to the browsers restrictions.

A: 

Could I trouble you and test a suspicion of mine?

Replace your first line with:

$(document).ready(function() {loadMessage()});

Also, I note that https://static.unifiedpost.com/apps/myup/customer/upmail/upmail_messages/up_mail_messages.properties returns a 404 error, while the en version works well. Is this intentional?

GlenCrawford
Hi, It does not print anything with your suggestion. And yes, i do not have a default messages one. I have with en, nl, de and fr. Does it needs a default one if i send it en version...?
Cristian Boariu
I've never used the plugin before, but having a default messages file as well as language-specific ones might be a worth a try.
GlenCrawford
A: 

i don't know what is you server return, so in php i just echo something like this :

$arg = 'up.mail.test=messages loaded from en';
exit($arg);

then the js :

.......
callback: function() {
    var messageKey = up.mail.test;
    //alert(eval(messageKey));
   jQuery('#customMessage').html(jQuery.i18n.prop(messageKey));
}

i got this : [messages loaded from en] . is this what you want ?

Puaka
notice the up.mail.test is without " ' "
Puaka
Yes, this is what i want...Do not understand why it does not find my properties file on that hosts...Tried without '' too but it prints nothing in this case...extremely strange..
Cristian Boariu
when i change the path to http://static.unifiedpost.com/apps/myup/customer/upmail/upmail_messages/up_mail_messages_en.properties, got Access Denied error, but still dispay "test" as the return result
Puaka
if you have firebug, check for error in console panel, else use chrome developer tools, see if got error
Puaka
Yes, checked with Firebug no error. The same result: [up.mail.test]
Cristian Boariu
hmm this is weird. you might want to try it on localhost, as i was testing the code using simple php , <?php $arg = 'up.mail.test=messages loaded from en';exit($arg);?> just that 2 lines
Puaka
After testing locally, all works good. But if the messages files are located to another host (like in the above example) it seems that it fails...It would be nice if anyone can confirm this...
Cristian Boariu