Core: base href="/..." isn't taking into account

Created on 25 Feb 2018  路  3Comments  路  Source: ngx-translate/core

I'm submitting a ...

[ 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
Everything working perfectly in dev / locahost when working with ng serve (npm start). When I publish in production the tag "base href=" isn't taking into account in order to get the correct path to /assets/i18n/...
Look like it isn't a problem of my Angular project as I'm using this "base href=" to resolve correct path of some picture that are located into /assets/img/ and it's perfectly working.

Expected/desired behavior
Files under /i18n should resolve correct path with "base href=" or another system.

Reproduction of the problem

app.module.ts

export function HttpLoaderFactory(http: HttpClient) { return new TranslateHttpLoader(http); }
...
imports: [ TranslateModule.forRoot({ loader: { provide: TranslateLoader, useFactory: HttpLoaderFactory, deps: [HttpClient] } }),

In my "head" tag HTML page:
<base href="http://localhost:8888/wordpress/wp-content/plugins/sagenda-calendar-wp/assets/angular/" />

Build cmd : ng build --prod --aot
Code is published as a WordPress plugin there : https://github.com/Sagenda/sagenda-calendar-wp

Error on the page:
polyfills.bundle.js:1 GET http://localhost:8888/assets/i18n/en.json 404 (Not Found)

But my pictures such as:
<img _ngcontent-c0="" alt="list" height="25" src="./assets/img/octicons/svg/list-unordered.svg" width="25">
are solved without problem...

Please tell us about your environment:
MacOS X 10.13.3

  • ngx-translate version: 9.1.1
  • ngx-translate/http-loader version: 2.0.1
  • Angular version: 5.2.6
  • Browser:
    [ Tested under : Chrome 64.0.3282.167 | Firefox Developer Edition 59.0b12 (64-bit)|Safari 11.0.3 (13604.5.6) ]

Most helpful comment

You can set the loader path as 2nd parameter of the TranslateHttpLoader:

export function HttpLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http, "./assets/i18n/");
}

The default prefix is /assets/i18n/ - this is why they are loaded from the root assets folder.

All 3 comments

You can set the loader path as 2nd parameter of the TranslateHttpLoader:

export function HttpLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http, "./assets/i18n/");
}

The default prefix is /assets/i18n/ - this is why they are loaded from the root assets folder.

Having the assets folder directly under the src folder worked for me. Since I wrongly had it nested in an app folder

Default should be changed to ./assets/i18n/. Makes not sense to hardcode it to /assets/i18n/. Please reopen @CodeAndWeb

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Snap252 picture Snap252  路  3Comments

egornoveo picture egornoveo  路  4Comments

jstoup111 picture jstoup111  路  4Comments

louisdoe picture louisdoe  路  3Comments

gmquiroga picture gmquiroga  路  3Comments