Skip to content

Instantly share code, notes, and snippets.

Last active May 11, 2023 07:01
  • Star 19 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
ng2-translate file loader for Angular Universal (server side)
import {TranslateLoader} from "ng2-translate/ng2-translate";
import {Observable} from "rxjs/Observable";
import fs = require('fs');
export class TranslateUniversalLoader implements TranslateLoader {
constructor(private prefix: string = 'i18n', private suffix: string = '.json') {}
* Gets the translations from the server
* @param lang
* @returns {any}
public getTranslation(lang: string): Observable<any> {
return Observable.create(observer => {`${this.prefix}/${lang}${this.suffix}`, 'utf8')));
Copy link

all2pie commented Sep 21, 2021

custom-translate-loader.ts for latest rxjs:

import { of } from 'rxjs';
import { en } from '../../../assets/i18n/en';
import { ar } from '../../../assets/i18n/ar';
import { TranslateLoader } from '@ngx-translate/core';

export class CustomTranslateLoader implements TranslateLoader {
  public getTranslation(lang: string) {
    if (lang === 'ar') {
      return of(ar);
    return of(en);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment