Open aftoncreative opened 3 years ago
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?
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?
Thank you for hint with this calling in app component, saved my day!
Well in the end, i moved on something else what is working on website too. https://github.com/ngx-translate/core
@PavelSuk98 ngx-translate works on native script angular?
I am also facing same issue , language change not working on android, ios its working fine
Yers it is working on android and i would say it will work on IOS too that ngx-translate
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!
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!
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...
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.