I was using this library ngx-translate-multi-http-loader to being able to load multiple language file for my ionic 5 App.
I didn't had any errors, but the translation wasn't working.
Then I added inside the TranslateModule.forRoot({}) the defaultLanguage: 'en', and it then resulted in the following error message
Something went wrong for the following translation file: ./assets/i18n/en.json
Database not created. Must call create() first
I needed a lot of time to figure it out how to fix it and couldn't find no help on internet.
2023 Fix
This error shouldn't happen anymore with >= 9.2.0. Since the library is now using
httpBackendThe error
This topic pointed me in the right direction. Basically, the required loader that we use to import the translations files
Is directly imported into the app.module.ts @ngModule
If you find this post, it surely mean you're using an
HttpInterceptorin your app, that does request the data from the ionic storage (or any other services) to apply a specific logic to the request -> Let say, you want to add a token to the request.Let's have the following example
Then, because the
ngx-translate-multi-http-loaderis requesting the translations file with the angular defaulthttpclass, you'll be passing through this http interceptor. But the_storageisn't instantiated yet. which result in anDatabase not created. Must call create() firstwhich make our request fail into theSomething went wrong for the following translation file: ./assets/i18n/en.jsonThe fix
We have to ignore this interceptor for that specific request.
For that purpose :
you could do it with a
httpBackend-> here an explanation. But it wont work, because you wont have instantiate your services before the http call.You have to add a specific header, that tell your
HttpInterceptorto ignore the request and let it going through without further investigation. Thx JohnrSharpeFor being able to pass that header into the
ngx-translate-multi-http-loader, well.. you can't. because the library do not accept it, but it isn't complicated to copy it.And there you are.