Skip to content

Support for Auto Page Title with I18n #8

Description

@blimmer

Thanks for this project, it's awesome to not have to have @machty 's source just copy/pasted into our project anymore.

We originally modified the gist just slightly to allow automatically providing a page title in our Ember I18n translation file so we didn't need to create a route file simply to provide a title or titleToken.

To get it working with this add-on we made use of an initializer to support the auto-lookup. Something like this:

import Ember from 'ember';

export function initialize(/* container, application */) {
  Ember.Route.reopen({
    titleToken: Ember.computed('routeName', function() {
      var pageTitleKey = `pageTitles.${this.get(routeName)}`;
      if(Ember.I18n.exists(pageTitleKey)) {
        return Ember.I18n.t(pageTitleKey);
      }
    })
  });
}

export default {
  name: 'route',
  initialize: initialize
};

and then we provide a translation for the route name in our translations file, like this:

en = {
  pageTitles: {
    application: 'My Page Name'
    ...
  }
}

I'm happy to keep-on-keepin' on with our custom re-open but I was curious if this sort of thing would be helpful for anyone else using this project.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions