Skip to content

Instantly share code, notes, and snippets.

@itayod
Created December 8, 2019 08:47
Show Gist options
  • Save itayod/6838cc125f788171bb70996abdf7c2f1 to your computer and use it in GitHub Desktop.
Save itayod/6838cc125f788171bb70996abdf7c2f1 to your computer and use it in GitHub Desktop.
@Injectable({ providedIn: 'root' })
export class HttpLoader implements TranslocoLoader {
contructor(private http: HttpClient) {}
getTranslation(lang: string, { scope }) {
const base = this.http.get(`/assets/i18n/${lang}.json`);
if(scope) {
return base;
}
return forkJoin([
base,
this.http.get(`/assets/i18n/${lang}.vendor.json`)
]).pipe(
map(([translation, vendor]) => {
return { ...translation, ...vendor }
})
)
}
}
export const httpLoader = {
provide: TRANSLOCO_LOADER,
useClass: HttpLoader
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment