Skip to content
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

Nativescript/Angular - Localize-function does not apply the new localizations after overridelocale #98

Open
aftoncreative opened this issue Aug 26, 2020 · 9 comments

Comments

@aftoncreative
Copy link

I am running into issues with the overridelocale-method.

After overriding the locale and restarting the application, the localizations done on the template with {{'Localizationstring: L}} seem to be correctly updated but all the content I have added using the localize()-function on the TypeScript are not updated and continue showing the default localization.

@aftoncreative
Copy link
Author

I have been debugging this and I have realised this issue occurs when the localize-functions are called before the androidLaunchEventLocalizationHandler(); is complete.

I have content that is localized on app start-up using the localize()-function.

Is there a hook to attach this function somewhere where it will ran before the rest of the application is loaded? Anyone has a workaround for this kind of situations?

@aftoncreative
Copy link
Author

Okay, so for anyone else running into same issues.

I noticed that the launch-event that the documentation tells to hook the androidLaunchEventHandler-is triggered much later that for example AppComponent constructor.

What I did I ran the androidLaunchEventHandler-function on AppComponent constructor. That solves the issue that I described earlier. What was weird is that with this function call only in AppComponent, the translations using the L-pipe on templates did not work anymore. Then I added the function call also the main.ts and I got also those working. '

So now I am calling this function twice to make everything work correctly. Not sure if this results in some other errors or if this is very bad for performance. Any ideas anyone?

@pavel-suk
Copy link

pavel-suk commented Sep 7, 2020

Thank you for hint with this calling in app component, saved my day!

@pavel-suk
Copy link

Well in the end, i moved on something else what is working on website too.
https://github.com/ngx-translate/core

@itsmerockingagain
Copy link

@PavelSuk98 ngx-translate works on native script angular?

I am also facing same issue , language change not working on android, ios its working fine

@pavel-suk
Copy link

pavel-suk commented Dec 4, 2020

Yers it is working on android and i would say it will work on IOS too that ngx-translate

@ReazerDev
Copy link

ReazerDev commented Apr 4, 2021

For me, it was enough to place androidLaunchEventLocalizationHandler into the AppComponent and removing it from my main.ts. I don't have any problems with the pipe in my views.
Thank you @aftoncreative!

@AdrianHavengaBennett
Copy link

AdrianHavengaBennett commented Feb 15, 2022

As @ReazerDev has said, for me it was exactly the same. Remove androidLaunchEventLocalizationHandler() from main.ts and add it into the AppComponent's constructor instead. Thanks, @aftoncreative, I wish I found your solution a few days ago!

@lano-vargas
Copy link

lano-vargas commented Sep 28, 2023

Same issue here, I've tried few option state here but in AppComponent's constructor didn't work at all. The issue is when you first run the app e.g ns run --device xxxxxxx the translation does not kick in, but after a file is modified it works also works if you move from one page to another then the translation work as well, really weird that the translation doesn't work right on after ns run ... Have anyone a found a solution?

UPDATE:

It actually works in app.component.ts constructor but the devil is in the detail as the documentation suggest this:

Application.on(Application.launchEvent, args => {
  if (args.android) {
    androidLaunchEventLocalizationHandler()
  }
})

And that doesn't work, what works for me as much simpler:

if (isAndroid) {
      console.log('Is Android in app component constructor');
      androidLaunchEventLocalizationHandler()
    }
    const localeOverriddenSuccessfully = overrideLocale('de'); 

And that's all, no need duplication in main.ts etc...

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

6 participants