mercredi 2 septembre 2015

ember: dynamic language in templates. use LanguageController?

I have an ember app written in pre 1.0 ember. I want to re-write the app in ember 2.0.

In the old codebase I have an LanguageController that have english defintions of all langauge strings, and I have an ajax call to populate the language controller with strings from another language. I then have that controller available as a global variable available in all templates. An ember 2.0 template may look like this:

<label id="lblHomeNextAppointment">{{EEA.lang.home_next_appointment}}</label>
    <div class="appointment">
        {{model.nextAppointment.formattedDate}}
        {{model.nextAppointment.title}}
    </div>

I want to put the dynamic language string where it says EEA.lang.home_next_appointment.

How to structure controllers etc. to achieve this? Maybe use a service? Whats the fundamental difference between a controller and a service?

The old (pre 1.0) controller looks like this:

EEA.LanguageController = Ember.ArrayController.extend({
    // Default values for language strings
    "header_progress": 'Progress',
    "header_planned": 'Planned',
    "home_next_appointment": "Next Appointment",
...
    init: function() {
        this._super();
        EEA.lang = this;  // Shorter to write EEA.lang, than EEA.router.languageController
    },
...




Aucun commentaire:

Enregistrer un commentaire