Hwo to dynamically load and read locale files from i18n folder

5,348 views
Skip to first unread message

TP

unread,
Nov 26, 2012, 10:56:49 AM11/26/12
to ang...@googlegroups.com
Hi

I have created a service (as below) and able to load the locale (culture : german,chinese etc)\but unable to read the date formats
Is there anyway to do this?

  $http.
                    get('app/lib/angular/i18n/angular-locale_' + culture + '.js').
                    success(function (response) {
                        window.alert(response);
                   
                        eval(response);
                    }).
                    error(function(response) {
                        console.log('Unable to locate AngularJS locale resource.');
                    });

Johannes Hiemer

unread,
Nov 27, 2012, 4:19:17 AM11/27/12
to ang...@googlegroups.com
Hi,
how are you trying to parse the stuff into your page? Could you create a plnkr?


Regards,
Johannes

TP

unread,
Nov 27, 2012, 2:23:41 PM11/27/12
to ang...@googlegroups.com
Hi Johannes

Below is the function and HTML which calls the service I mentioned in my question.
Whenever I click sepeific language, the localeContenturl - contains a sample HTML page (contains a var --> localess ) , which loads the data returned from the service

Could you please look into this?

function EquipmentControl($scope, $locale, localeService) {
    
    $scope.locale = $locale.id;

    $scope.changeLanguage = function(culture) {
        localeService.getResources(culture).then(function (localeResources) {
       $scope.localess = localeResources;
        });
    };
    $scope.localeContentUrl = '/app/partials/Templates/home.html';
};
   HTML
<div ng-controller="EquipmentControl">


    <p>Change language: <a ng-click="changeLanguage('en')">English </a> | <a ng-click="changeLanguage('zh')">Chinese </a> | <a ng-click="changeLanguage('de')">German </a>   </p>
    <div ng-include src="localeContentUrl"></div>
 
 </div>

Johannes Hiemer

unread,
Nov 27, 2012, 4:13:16 PM11/27/12
to ang...@googlegroups.com
Hi,
what you are trying to do won't work. AngularJS currently only allows to inject the i18n stuff in the config phase. I have created another sample which works with filter, but could lead into performance issues. Take a look here:


Regards,
Johannes


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
 
 



--
Mit freundlichen Grüßen

Johannes Hiemer

TP

unread,
Nov 27, 2012, 6:15:48 PM11/27/12
to ang...@googlegroups.com
Hi Johannes.

Thanks for your piece of work. I really appreciate that.

As you said, there is no way we can inject in runtime using Angular.

Have you ever tried using RequireJs or any other technologies? I am researching on that

Thanks

Thulasi

Johannes Hiemer

unread,
Nov 28, 2012, 5:22:51 AM11/28/12
to ang...@googlegroups.com
Hi Thulasi,
nope haven't done that yet. But I would be really interested in other workarounds. I had a brief chat with Pawel last week, about the performance issues occurring, when using filters, so this is just a sample, but no really a production ready implementation. What would be cool, is to get some performance stats of the filter method and work on some other workarounds for the feature-lacking i18n implementation.

Regards,
Johannes

TP

unread,
Nov 28, 2012, 8:08:37 AM11/28/12
to ang...@googlegroups.com
Hello Johannes,

That sounds really great. Hopefully next version of angular js will have better support. Thanks for helping me out.

Regards

Thulasi

Mark Volkmann

unread,
Oct 7, 2013, 6:28:29 PM10/7/13
to ang...@googlegroups.com
I found this AngularJS module that handles dynamic locale changes perfectly!

Gary Bisaga

unread,
Apr 4, 2014, 12:48:56 PM4/4/14
to ang...@googlegroups.com
This looks very nice. Thanks for the reference!
Reply all
Reply to author
Forward
0 new messages