Multiple lang files
fplini opened this issue ยท 6 comments
Hi, is there a way to split a single lang file?
I have my lang files that is going to be very large and I want to split these into multiple files for each lang.
Is it possible?
Thanks
Fabrizio
Hi @tiaguinho thanks for reply.
I'm using the TranslateHttpLoader, Do you mean that I can load an array of files (suffix)?
Sorry @fplini, I think I have read wrong the first time.
I think it's not possible split the translates between files, by default.
Tell me one thing, do you use webpack in your project?
Hi @tiaguinho
I'm using angular cli to build my project so the answer is "yes"
HI, I'm using a multi translate custom class
`import { HttpClient } from '@angular/common/http';
import { TranslateLoader } from '@ngx-translate/core';
import { forkJoin } from 'rxjs';
import { map } from 'rxjs/operators';
import * as R from 'ramda';
import { environment } from '../../environments/environment';
export function translateLoader(http: HttpClient) {
return new MultiTranslateHttpLoader(http, [
{ prefix: './assets/i18n/', suffix: '.json' },
{ prefix: environment.translateDir, suffix: '.json' },
]);
}
export class MultiTranslateHttpLoader implements TranslateLoader {
constructor(
private http: HttpClient,
public resources: { prefix: string, suffix: string }[] = [{ prefix: '/assets/i18n/', suffix: '.json' }]) {}
public getTranslation(lang: string): any {
return forkJoin(this.resources.map(config => {
return this.http.get(${config.prefix}${lang}${config.suffix}
);
})).pipe(map(response => {
return response.reduce((a, b) => {
return R.mergeDeepLeft(a, b); // Object.assign(a, b);
});
}));
}
}
`
It loads an array of json, and merge those with ramda, If you didnt use nested objects you could also use Object.assign()
I've created a lib for this:
https://github.com/larscom/ngx-translate-module-loader