Datetime is not localized when script loaded asynchroniously

107 views
Skip to first unread message

Sergey Z

unread,
Jul 29, 2013, 7:09:57 AM7/29/13
to ang...@googlegroups.com
Hi all,

I am trying to load this script asynchroniously via $http.get(script_url), but changes for specific locale seems to be not applied.

angular.module("ngLocale", [], ["$provide", function($provide) {
   $provide.value("$locale", {
        "DATETIME_FORMATS": {
            "AMPMS": {
                "0": "\u4e0a\u5348",
                "1": "\u4e0b\u5348"
            },
            "DAY": {
                "0": "\u661f\u671f\u65e5",
                "1": "\u661f\u671f\u4e00",
                "2": "\u661f\u671f\u4e8c",
                "3": "\u661f\u671f\u4e09",
                "4": "\u661f\u671f\u56db",
                "5": "\u661f\u671f\u4e94",
                "6": "\u661f\u671f\u516d"
            },
            "MONTH": {
                "0": "1\u6708",
                "1": "2\u6708",
                "2": "3\u6708",
                "3": "4\u6708",
                "4": "5\u6708",
                "5": "6\u6708",
                "6": "7\u6708",
                "7": "8\u6708",
                "8": "9\u6708",
                "9": "10\u6708",
                "10": "11\u6708",
                "11": "12\u6708"
            },
            "SHORTDAY": {
                "0": "\u5468\u65e5",
                "1": "\u5468\u4e00",
                "2": "\u5468\u4e8c",
                "3": "\u5468\u4e09",
                "4": "\u5468\u56db",
                "5": "\u5468\u4e94",
                "6": "\u5468\u516d"
            },
            "SHORTMONTH": {
                "0": "1\u6708",
                "1": "2\u6708",
                "2": "3\u6708",
                "3": "4\u6708",
                "4": "5\u6708",
                "5": "6\u6708",
                "6": "7\u6708",
                "7": "8\u6708",
                "8": "9\u6708",
                "9": "10\u6708",
                "10": "11\u6708",
                "11": "12\u6708"
            },
            "fullDate": "y\u5e74M\u6708d\u65e5EEEE",
            "longDate": "y\u5e74M\u6708d\u65e5",
            "medium": "yyyy-M-d ah:mm:ss",
            "mediumDate": "yyyy-M-d",
            "mediumTime": "ah:mm:ss",
            "short": "yy-M-d ah:mm",
            "shortDate": "yy-M-d",
            "shortTime": "ah:mm"
        }
    });
}]);

If I make an attempt to load it directly in index.html including it to <script type="text/javascript" src='scripts/i18n/angular-locale_zh.js'></script> -  it works correct
Here (http://blog.brunoscopelliti.com/internazionalization-i18n-with-angularjs) locale is getting from server side, but I need to define it on client side.

I also tried to use ngSrc directive for <script> tag (<script type="text/javascript" ngSrc='scripts/i18n/angular-locale_' + {{ locale }} + '.js'></script>),but no successful results.

Please give me a hint, what am doing wrong?

Sergey





Mike Alsup

unread,
Jul 30, 2013, 7:52:29 PM7/30/13
to ang...@googlegroups.com
If you're loading a script via $http.get() then you'd need to eval the response yourself.

Alternatively, you could inject a script tag into the DOM.










--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Lucas Galfaso

unread,
Jul 31, 2013, 5:46:16 PM7/31/13
to ang...@googlegroups.com
The right way would be to add the script tag to the DOM. An alternative would be using something like

Reply all
Reply to author
Forward
0 new messages