-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Auto Page Title with I18n #8
Comments
Hi again - sorry I didn't get to this sooner. I don't think this functionality belongs in this addon - there are multiple I18n-solutions for Ember and I'm not too keen on supporting everyone. Having to define a route to define a title is a separate issue though, and it might be worth looking in to that! I was first thinking that maybe the best way would be to implement the I like the title to be route and router-driven, so I'm not too sure about having some kind of title map either, although it might work. |
@kimroen Totally understood on not supporting all the i18n solutions out there for Ember. Spitballing here, but would we be able to set up "plugin" functionality of some kind to allow each i18n solution to provide the needed config as desired? That way, for this add-on, we'd only need to call the standard plugin interface, but it'd give folks the flexibility to customize this as desired ... |
@acorncom I love that idea and would help with an ember-i18n adapter. |
Sure. I'm very curious as to what you have in mind for that. I had a different thought though - how about allowing the user to define a default title token function? The user would define this in their router: Ember.Router.extend({
defaultTitleToken(routeName) {
// Parse the name and return whatever you want
if (Ember.I18n.exists(pageTitleKey)) {
return Ember.I18n.t(pageTitleKey);
}
}
}); Then in ember-cli-document-title's route-implementation, we could do something like this in collectTitleTokens: function(tokens) {
var titleToken = get(this, 'titleToken');
if (titleToken === null) {
titleToken = this.router.defaultTitleToken(get(this, 'routeName'));
} else if (typeof titleToken === 'function') {
titleToken = titleToken.call(this, get(this, 'currentModel'));
}
// The rest of the function
} Now, whenever a route that has no We might want to pass it the model and provide the context of the route instead of passing in the name, but I just wanted to communicate the idea. Thoughts on that? This way, it should be fairly trivial to do whatever you want. |
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
ortitleToken
.To get it working with this add-on we made use of an initializer to support the auto-lookup. Something like this:
and then we provide a translation for the route name in our translations file, like this:
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.
The text was updated successfully, but these errors were encountered: