analog: Can't load Transloco i18n files
Please provide the environment you discovered this bug in.
serve command “nx”: “16.8.0” “@angular/core”: “16.2.3” “@analogjs/platform”: “^0.2.0” “@analogjs/vite-plugin-angular”: “^0.2.0”
Which area/package is the issue in?
Don’t know / other
Description
I try to load transloco i18n files, but I have an unknown error (status 0). I load them from my assets folder, and as I understand, in SSG mode, we need to load those files with an absolute url, I hard coded the host, to test :
import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Translation, TranslocoLoader } from '@ngneat/transloco';
@Injectable({ providedIn: 'root' })
export class TranslocoHttpLoader implements TranslocoLoader {
private http = inject(HttpClient);
getTranslation(lang: string) {
return this.http.get<Translation>(
`http://localhost:5173/assets/i18n/${lang}.json`
);
}
}
In the terminal, I have the error, with the link (‘http://localhost:5173/assets/i18n/en.json’) which was in error, but when I click on the link, I can access to the file in the browser. I don’t understand how to solve that…
I need also to load svg spritesheet for angular material (MatIcon), but I don’t know understand yet how to get the hostname while server rendering…
Please provide the exception or error you saw
No response
Other information
No response
I would be willing to submit a PR to fix this issue
- Yes
- No
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (8 by maintainers)
Ok. Try using
@jsverse/**instead of just@jsverse/translocoHi @luishcastroc, Thanks for your answer. It seems I may have a specific problem due to my project. I’m working on an existing project and try to add Analog, and it seems to create strange problems… I tried it on a simpler project. And it almost works for me, in serve mode, yes, but not in build mode. I use AnalogJS to finally make SSG not SSR. I try to solve the problem with @brandonroberts , we discuss about it on Discord @brandonroberts created an Analog Transloco test project I checked also this Transloco SSR project The baseUrl is hard coded in environment file. I think I need to understand how to set the port when Server Side rendering and it will be ok. Have a nice day!