safely use translate.instant()
See original GitHub issueis theire a way to load translations when application starts so that we can safely use translate.instant()
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:27
Top Results From Across the Web
ngx-translate .instant returns key instead of value
I am trying to make a method which would accept string key and return translated string value by using translate.instant ...
Read more >Configuring ngx-translate to load at startup in Angular
So, basically, this is what you need to do in order to have instant translations in your app: preload translations using .use() method....
Read more >How To Use ngx-translate with Angular - DigitalOcean
The method translate. setDefaultLang('en') allows you to specify a fallback set of translations to use in case there are missing translations ...
Read more >How to translate your Angular app with ngx-translate
1. Add ngx-translate to your Angular application 2. Set up the TranslateService in your app.module.ts 3. Create your main language translation file (in...
Read more >ngx-translate Documentation - CodeAndWeb
Gets the instant translated value of a key (or an array of keys). This method is synchronous and the default file loader is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
All you need to do (as it was partially mentioned) is to preload translations using
.use()
method. The problem is the method is async (we should wait for the result). The best way to force the application to wait for “something” to finish before it shows up is usingAPP_INITIALIZER
function in yourAppModule
.You have to add following provider to your
AppModule
’sproviders
section:And define factory function
appInitializerFactory
upper in the same file:Now application will wait for translations initialization before it shows up for user.
Hi, I don’t know if this is the best solution but worked for me: string “init” is any key you want