AlexandreDz
AlexandreDz

Reputation: 41

Force template refresh ember.js

I'm using I18n localization package to take care of the switching language part of my app. It uses a global variable to set the language wanted and a json file to store the translations.

As the switching of a language is just a change in a global variable ember doesn't detect it and doesn't render the templates automatically. I forced it via an action in the application controller :

Extranet.ApplicationController = Ember.ObjectController.extend(
{
    actions:
    {
        localToFr: function()
        {

            this.localisation('fr'); // this changes the global variable
            this.get('target.router').refresh(); // this is what refresh the template
        },
        localToEn: function()
        {
            this.localisation('en');
            this.get('target.router').refresh();
        }
    },
    localisation: function(lg)
    {
        I18n.locale = lg;
    }
})

I have two problems with that solution : 1) The application template isn't rerendered via my

this.get('target.router').refresh();

2) And my other problem, it doesn't work on templates which don't request a server access ( e.g. : the nest of routes 'authSession' )

Extranet.Router.map(function()
    {
        this.resource(
            'parkings', {path:'/'}, function ()
            {
                this.route('parking', {path:'/parking/:parking_id'});
                this.route('historique', {path:'/parking/:parking_id/historique'});
                this.route('sessAct', {path:'/parking/:parking_id/sessAct'});
                this.route('rapport', {path:'/parking/:parking_id/rapport'});
            }
        );
        this.resource(
            'authSession', function ()
            {
                this.route('login');
                this.route('logout');
            }
        );
    }
);

Upvotes: 4

Views: 1874

Answers (1)

Louay Alakkad
Louay Alakkad

Reputation: 7408

I was having a similar issue. I just went with View.rerender() on the main view, which was a form in my case.

Upvotes: 1

Related Questions