-
Notifications
You must be signed in to change notification settings - Fork 184
Can't observe i18n.locale
in a component
#299
Comments
Which version of ember-i18n are you using? |
I'm using:
|
I'm surprised the observer doesn't fire on your component. It does in the helper. How are you switching locales? |
I'm using the wiki example, more or less: I turned it into a bootstrap default navbar dropdown button.
Template looks like: ...
<ul class="dropdown-menu" role="menu">
{{#each locales as |loc|}}
<li><a href="#" {{action "change" loc.id}}>{{loc.text}}</a></li>
{{/each}}
</ul> Logic looks like: const { Component, computed, inject } = Ember;
i18n: inject.service(),
...
actions: {
change: function(locId) {
this.get('i18n').set('locale', locId);
}
} I am using a computed property for that purpose in another component, and it works perfectly. I thus guess that the event is triggered... |
It's worth a shot, but I doubt that's the problem. Is the |
Yes: the refreshTooltips: function() {
Ember.run.scheduleOnce( 'afterRender', this, function() {
$('[data-toggle="tooltip"]').tooltip('fixTitle') ;
}) ;
}.observes('i18n.locale') The bug is still sounds real.
|
To add another data point, I also encountered this recently. I have a component that uses the |
Services are only materialized if you actually attempt to retrieve them. The helper (as @jamesarosen pointed out) works because it retrieves the service and uses it during its compute function (which happens as part of normal rendering in a helper). I could have missed it (I'm on mobile and couldn't see if there was a full demo/reproduction), but in the snippets above I don't see where the component is calling 'this.get("i18n")'. If the service is never retrieved it is never observed (well, actually it is, but it's value is always undefined). The manual injection via initializer works, because that forces the service to be instantiated when the object itself is instantiated (this is how the container/registry DI system works). |
In that case, you might be able to do the following: i18n: Ember.inject.service(),
didInitAttrs() {
this.get('i18n');
} |
@imbrou +1 for docs/wiki include. I could definitely see myself stumbling on this if not for this thread. |
The It does seem unintuitive/surprising that a |
I'm going to close this and add a comment to the wiki. |
Hi James, hi Kelly, hi dockyard, hi folks!
Using Bootstrap 3 tooltips in a component, I can't find a way to translate its content on a locale change.
Component's template:
Component's logic:
As you can see, the Bootstrap API makes use of the HTML
title
attribute to provide a good fallback to classic tooltips if needed. Then of course, to avoid double tooltips, the$().tooltip()
call saves its content, and empties the attribute.My problem is then the following:
My observer on
i18n.locale
is never triggered ; after a language switch, my "saved" tooltip content is never updated to the translated one.Concretely, after a (English ➜ Dutch) switch, I end up in this situation:
Fortunately, sounds like @kellyselden faced the same problem last year on @DockYard's fork. He even implemented a nice plugin proposing a pretty clean (?) workaround.
What about integrating it? Would somebody else be interested in this feature?
The text was updated successfully, but these errors were encountered: