Skip to content

$state.reload instead of broadcastUpdate? #242

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

Closed
vbraun opened this issue Nov 3, 2015 · 5 comments
Closed

$state.reload instead of broadcastUpdate? #242

vbraun opened this issue Nov 3, 2015 · 5 comments

Comments

@vbraun
Copy link

vbraun commented Nov 3, 2015

Background: I'm having some interop issues with angular-material, e.g. #214 or angular/material#1742. In both cases the initial render is ok, but subsequent changes of the language via setCurrentLanguage(...) don't produce the desired effect.

My current workaround is to just flip the language variable and reload the current state:

    gettextCatalog.currentLanguage = ...
    $state.reload()

I realize that this uses ui-router and loses content of <input> fields, on the other hand it is more robust since you only have to be able to render once. Another advantage is that you can use one-time bindings {{::"Text"|translate}}. Is there any other issue that I haven't thought about? Would there be interest to "bless" this workaround by adding a special setter setCurrentLanguageAndReload, say?

@rubenv
Copy link
Owner

rubenv commented Nov 4, 2015

I'm not sure why changes to angular-gettext are needed for this?

Can't you just add this to your application:

$rootScope.$on("gettextLanguageChanged", function () {
    $state.reload();
});

?

@rubenv
Copy link
Owner

rubenv commented Nov 4, 2015

Also note that there isn't currently a dependency on ui-router in angular-gettext (and we won't add one, not every project needs ui-router).

@vbraun
Copy link
Author

vbraun commented Nov 4, 2015

Good idea, I didn't think about overwriting the gettextLanguageChanged signal!

I'm still having some issues with

 <md-button translate>Text</md-button>

in angular-material. This is first hit by the angular-material compiler, which rewrites it to

 <md-button translate><span>Text</span></md-button>

and then angular-gettext can't extract the msgid. It should run first so it can access the untransformed "Text". And then it must not terminate so that angular-material can do its thing. I'm currently playing around with changing

     restrict: 'AE',
-    terminal: true,
-    terminal: false,
+    priority: 10000,
     compile: function compile(element, attrs) {

in the translate directive. Should this be configurable? I read #147 but I still don't know why it sets terminal=true right now.

@rubenv
Copy link
Owner

rubenv commented Dec 10, 2015

@vbraun That's a different discussion, which we should probably have in #147.

We could probably tweak both values, but I'm hesitant to do so because I'm not entirely sure what the effects might be (and I don't want to break existing code out there). If we can prove that it's safe: sure.

@rubenv
Copy link
Owner

rubenv commented Dec 10, 2015

As for the state switching, that seems solved, so I'll be closing this issue (feel free to reopen if needed).

@rubenv rubenv closed this as completed Dec 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants