mardi 28 juillet 2015

Ember 1.13 - Recompute helper when ENV variable change

I got a "get-text" helper which translate my static fields depending on a config variable : ENV.LOCALE.

The thing is, I'd like to recompute my if my ENV.LOCALE gets modified. I tried several things from sending events to Ember.observer, without much success.

// controllers/application.js
locale: function() {
    var locale = this.get('isFrench') === true ? 'fr' : 'en';
    ENV.LOCALE = locale;

    return locale;
}.property('isFrench'),    


//helpers/get-text.js
import Ember from 'ember';
import ENV from '../config/environment';

export default Ember.Helper ( function(key, locale) {
    var lang = {
        save: {
            'fr': 'Enregistrer',
            'en': 'Save',
        },
    }
    return new Ember.Handlebars.SafeString(lang[key][ENV.LOCALE]);
});

Bottom line, how can I recompute my helper when a global property changes?




Aucun commentaire:

Enregistrer un commentaire