Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Multiple lang files #44

Open
fplini opened this issue Mar 21, 2018 · 6 comments
Open

Multiple lang files #44

fplini opened this issue Mar 21, 2018 · 6 comments

Comments

@fplini
Copy link

fplini commented Mar 21, 2018

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

@tiaguinho
Copy link

@fplini The example we have in the README file show exactly how to do this.

@fplini
Copy link
Author

fplini commented Mar 28, 2018

Hi @tiaguinho thanks for reply.
I'm using the TranslateHttpLoader, Do you mean that I can load an array of files (suffix)?

@tiaguinho
Copy link

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?

@fplini
Copy link
Author

fplini commented Apr 11, 2018

Hi @tiaguinho
I'm using angular cli to build my project so the answer is "yes"

@danielhanzs
Copy link

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()

@larscom
Copy link

larscom commented Mar 19, 2019

I've created a lib for this:
https://github.com/larscom/ngx-translate-module-loader

gopal-jayaraman added a commit to gopal-jayaraman/http-loader that referenced this issue Feb 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants