Core: Getting 404 Not Found for translation files.

Created on 15 Feb 2017  路  7Comments  路  Source: ngx-translate/core

I'm submitting a ... (check one with "x")

[x] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior
Receiving this error message in console output:
EXCEPTION: Response with status: 404 Not Found for URL: /assets/i18n/en-us.json

Expected/desired behavior
No error message

Reproduction of the problem
I've followed the readme exactly and have been struggling for a few hours to get this working. Using the translate.setTranslations method works, but using the HTTP loader does not.

What is the expected behavior?
Translation files are loaded properly.

What is the motivation / use case for changing the behavior?
Doesn't work.

Please tell us about your environment:

  • ngx-translate version: 6.0.0

  • Angular version: 2.4.0

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

All 7 comments

It looks like the tool you are using to build your application doesn't copy your translation files. Make sure the file en-us.json exists in the directory assets/i18n. If not, make sure you copy them over to the dist directory.

Sorry, I just figured it out. The InMemoryWebApiModule was intercepting the HTTP loader's request. Thanks for the quick reply!

how to fix ?

@LeHoanVu if you're using the InMemoryWebApiModule for mock network requests, you'll need to remove it. In my case I ended up writing my own static loader to ensure that everything is loaded before attempting to process translation keys.

Elliot. Is it possible that you share some more information regarding your static loader? I'm new to angular and found exactly this problem. My application is running perfectly but if I add the InMemoryWebApiModule in the app.module like this "InMemoryWebApiModule.forRoot(InMemoryDataService)," i get an error that my json translations files are not found.

I would truly appreciate your help with this.

Hey @mike1130694 , I unfortunately cannot share any code with you as I'm legally not allowed and the repository is private. I can tell you though that you add a reference to your synchronous loader class in the app module, where you would normally import the TranslateModule. For the synchronous loader class, it's simply an Observable that resolves immediately, and inside you load the translation json file. I'm pretty new to Angular myself so I know how tricky it can be. However, Angular 4 now includes a translation library which may be easier to implement than a synchronous loader for this module. Check it out here: https://angular.io/guide/i18n

I had the same problem, I found I could resolve it by setting the in-memory-web-api passThruUnknownUrl config flag to true to pass the request to the real url if a matching db collection name is not found.

Alternatively custom handling can be provided in your InMemoryDbService implementation.

Was this page helpful?
0 / 5 - 0 ratings