@ngx-translate/core#TranslateLoader TypeScript Examples

The following examples show how to use @ngx-translate/core#TranslateLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: test.utils.ts    From WowUp with GNU General Public License v3.0 7 votes vote down vote up
export function createTranslateModule(): ModuleWithProviders<TranslateModule> {
  return TranslateModule.forRoot({
    loader: {
      provide: TranslateLoader,
      useFactory: testHttpLoaderFactory,
      deps: [HttpClient],
    },
    compiler: {
      provide: TranslateCompiler,
      useClass: TranslateMessageFormatCompiler,
    },
  });
}
Example #2
Source File: i18n.constants.ts    From geonetwork-ui with GNU General Public License v2.0 6 votes vote down vote up
TRANSLATE_DEFAULT_CONFIG = {
  compiler: {
    provide: TranslateCompiler,
    useClass: TranslateMessageFormatCompiler,
  },
  loader: {
    provide: TranslateLoader,
    useFactory: HttpLoaderFactory,
    defaultLanguage: DEFAULT_LANG,
    deps: [HttpClient],
  },
}
Example #3
Source File: app.module.ts    From ledge with Mozilla Public License 2.0 6 votes vote down vote up
@NgModule({
  declarations: [
    AppComponent,
    PatternComponent,
    ManualComponent,
    ResourcesComponent,
    ToolsetComponent,
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    SharedModule,
    AppRoutingModule,
    HttpClientModule,
    BrowserAnimationsModule,
    CustomMaterialModule,
    LedgeRenderModule,
    ScullyLibModule,
    FlexLayoutModule,
    TranslateModule.forRoot({
      defaultLanguage: 'zh-cn',
      loader: {
        provide: TranslateLoader,
        useClass: WebpackTranslateLoader,
      },
      // loader: {
      //   provide: TranslateLoader,
      //   useFactory: createTranslateLoader,
      //   deps: [HttpClient],
      // },
    }),
  ],
  providers: [Title],
  bootstrap: [AppComponent],
})
export class AppModule {}
Example #4
Source File: alert-dialog.component.spec.ts    From WowUp with GNU General Public License v3.0 6 votes vote down vote up
describe("AlertDialogComponent", () => {
  let linkService: any;

  beforeEach(async () => {
    linkService = jasmine.createSpyObj("LinkService", [""], {});

    await TestBed.configureTestingModule({
      declarations: [AlertDialogComponent],
      imports: [
        MatModule,
        NoopAnimationsModule,
        HttpClientModule,
        TranslateModule.forRoot({
          loader: {
            provide: TranslateLoader,
            useFactory: httpLoaderFactory,
            deps: [HttpClient],
          },
          compiler: {
            provide: TranslateCompiler,
            useClass: TranslateMessageFormatCompiler,
          },
        }),
      ],
      providers: [
        { provide: MAT_DIALOG_DATA, useValue: {} },
        { provide: MatDialogRef, useValue: {} },
        { provide: LinkService, useValue: linkService },
      ],
    }).compileComponents();
  });

  it("should create", () => {
    const fixture = TestBed.createComponent(AlertDialogComponent);
    expect(fixture.componentInstance).toBeTruthy();
  });
});
Example #5
Source File: app.module.ts    From tabby with MIT License 6 votes vote down vote up
@NgModule({
  declarations: [AppComponent, SidebarComponent, SettingsComponent, TimetableComponent, TasksComponent, NewLessonComponent, EditLessonComponent, HoldDeleteDirective, NewTaskComponent, SafeHtmlPipe, EditTaskComponent],
  imports: [
    BrowserModule,
    ReactiveFormsModule,
    HttpClientModule,
    AppRoutingModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient]
      }
    })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}
Example #6
Source File: features.module.ts    From coronatest with GNU Affero General Public License v3.0 6 votes vote down vote up
@NgModule({
	declarations: [
		FormComponent,
		LandingComponent,
		ChipComponent,
		ResultsComponent,
		LoadingEllipsisComponent,
		InfoComponent
	],
	imports: [
		DashboardModule,
		CommonModule,
		MatRadioModule,
		MatFormFieldModule,
		ReactiveFormsModule,
		FormsModule,
		MatInputModule,
		BrowserAnimationsModule,
		MatCheckboxModule,
		MatButtonToggleModule,
		MatStepperModule,
		HttpClientModule,
		TranslateModule.forChild({
			loader: {
				provide: TranslateLoader,
				useFactory: HttpLoaderFactory,
				deps: [HttpClient]
			}
		}),
		MatButtonModule,
		MatCardModule,
		MatSelectModule,
		RouterModule,
		MatProgressSpinnerModule
	]
})
export class FeaturesModule {}
Example #7
Source File: progress-spinner.component.spec.ts    From WowUp with GNU General Public License v3.0 6 votes vote down vote up
describe("ProgressSpinnerComponent", () => {
  let component: ProgressSpinnerComponent;
  let fixture: ComponentFixture<ProgressSpinnerComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [ProgressSpinnerComponent],
      imports: [
        MatModule,
        NoopAnimationsModule,
        HttpClientModule,
        TranslateModule.forRoot({
          loader: {
            provide: TranslateLoader,
            useFactory: httpLoaderFactory,
            deps: [HttpClient],
          },
          compiler: {
            provide: TranslateCompiler,
            useClass: TranslateMessageFormatCompiler,
          },
        }),
      ],
      schemas: [CUSTOM_ELEMENTS_SCHEMA],
    }).compileComponents();

    fixture = TestBed.createComponent(ProgressSpinnerComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it("should create", () => {
    expect(component).toBeTruthy();
  });
});
Example #8
Source File: app.module.ts    From coronatest with GNU Affero General Public License v3.0 6 votes vote down vote up
@NgModule({
    declarations: [
        AppComponent,
    ],
    imports: [
        BrowserModule,
        AppRoutingModule,
        FeaturesModule,
        CoreModule,
        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                useFactory: HttpLoaderFactory,
                deps: [HttpClient]
            }
        }),
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule {
}
Example #9
Source File: i18n.constants.ts    From geonetwork-ui with GNU General Public License v2.0 6 votes vote down vote up
TRANSLATE_GEONETWORK_CONFIG = {
  compiler: {
    provide: TranslateCompiler,
    useClass: TranslateMessageFormatCompiler,
  },
  loader: {
    provide: TranslateLoader,
    useClass: Gn4TranslateLoader,
    deps: [ToolsApiService],
  },
}
Example #10
Source File: translation.module.ts    From xBull-Wallet with GNU Affero General Public License v3.0 6 votes vote down vote up
static forRoot(): ModuleWithProviders<TranslateModule> {
    return TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient],
      }
    });
  }
Example #11
Source File: gn4.translate.loader.ts    From geonetwork-ui with GNU General Public License v2.0 6 votes vote down vote up
@Injectable({
  providedIn: 'root',
})
export class Gn4TranslateLoader implements TranslateLoader {
  constructor(private toolsApiService: ToolsApiService) {}

  getTranslation(lang: string): Observable<any> {
    // FIXME: need to filter translation with {{}} pattern
    // legacy from AngularJs, the api should handle it
    return this.toolsApiService.getTranslationsPackage1('gnui').pipe(
      map((json) =>
        Object.keys(json).reduce((translations, key) => {
          const value = json[key]
          if (!value.includes(' {{')) {
            translations[key] = value
          }
          return translations
        }, {})
      )
    )
  }
}
Example #12
Source File: get-addon-list-item-file-prop.pipe.spec.ts    From WowUp with GNU General Public License v3.0 6 votes vote down vote up
describe("GetAddonListItemFilePropPipe", () => {
  let component: TestAddonListItemFilePropComponent;
  let fixture: ComponentFixture<TestAddonListItemFilePropComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [TestAddonListItemFilePropComponent, GetAddonListItemFilePropPipe],
      imports: [
        HttpClientModule,
        TranslateModule.forRoot({
          loader: {
            provide: TranslateLoader,
            useFactory: httpLoaderFactory,
            deps: [HttpClient],
          },
          compiler: {
            provide: TranslateCompiler,
            useClass: TranslateMessageFormatCompiler,
          },
        }),
      ],
    }).compileComponents();

    fixture = TestBed.createComponent(TestAddonListItemFilePropComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it("should create", () => {
    expect(component).toBeTruthy();
  });
});
Example #13
Source File: app.module.ts    From Elastos.Essentials.App with MIT License 6 votes vote down vote up
/**
 * NOTE: BPI 20210226: Tried to have one translation loader per dapp module, using forChild / isolate,
 * but this doesn't work. Only forRoot() seems to load stuff, and only one forRoot() works, etc.
 * So for now, we load and merge all translations here.
 */
class CustomTranslateLoader implements TranslateLoader {
  public getTranslation(lang: string): Observable<any> {
    return new Observable<any>(observer => {
      void TranslationsLoader.getTranslations(lang).then((translations) => {
        observer.next(translations);
        observer.complete();
      })
    });
  }
}
Example #14
Source File: app.module.ts    From t3mpl-editor with MIT License 6 votes vote down vote up
@NgModule({
	declarations: [
		AppComponent
	],
	imports: [
		BrowserModule,
		EditorModule,
		HttpClientModule,
		TranslateModule.forRoot({
			loader: {
				provide: TranslateLoader,
				useFactory: HttpLoaderFactory,
				deps: [HttpClient]
			},
			defaultLanguage: 'en'
		})
	],
	providers: [],
	bootstrap: [AppComponent]
})
export class AppModule {
}
Example #15
Source File: ledge-editor.component.spec.ts    From ledge with Mozilla Public License 2.0 6 votes vote down vote up
describe('LedgeHelperComponent', () => {
  let component: LedgeEditorComponent;
  let fixture: ComponentFixture<LedgeEditorComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        SharedModule,
        LedgeEditorModule,
        TranslateModule.forRoot({
          loader: {
            provide: TranslateLoader,
            useClass: TranslateFakeLoader,
          },
        }),
      ],
      declarations: [LedgeEditorComponent],
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(LedgeEditorComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});
Example #16
Source File: translation.module.ts    From xBull-Wallet with GNU Affero General Public License v3.0 6 votes vote down vote up
static forChild(): ModuleWithProviders<TranslateModule> {
    return TranslateModule.forChild({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient],
      },
      extend: true,
    });
  }
Example #17
Source File: app.module.ts    From ng-devui-admin with MIT License 6 votes vote down vote up
@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    HttpClientModule,
    AppRoutingModule,
    CoreModule.forRoot(),
    SharedModule.forRoot(),
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useClass: I18NLoader,
      },
    }),
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}
Example #18
Source File: layout.module.ts    From dbm with Apache License 2.0 6 votes vote down vote up
@NgModule({
  declarations: [
    LayoutComponent,
    HeaderComponent
  ],
  imports: [
    LayoutRouting,
    FormsModule,
    CommonModule,
    NgZorroAntdModule,
    MarkdownModule.forRoot(),
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: httpLoaderFactory,
        deps: [HttpClient]
      }
    })
  ],
  providers: [
    BasicService,
    DatasourceService,
    HttpService,
    SshService,
    PrestoService,
    FactoryService
  ]
})
export class LayoutModule {
}
Example #19
Source File: app.module.ts    From mylog14 with GNU General Public License v3.0 6 votes vote down vote up
@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    AppRoutingModule,
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (LanguageLoader),
        deps: [HttpClient],
      }
    }),
    CoreModule,
    SharedModule,
    LottieModule.forRoot({ player: playerFactory }),
    ReactiveFormsModule,
    FormlyModule.forRoot(),
    FormlyIonicModule
  ],
  providers: [
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
Example #20
Source File: app.module.ts    From casual-chess with GNU General Public License v3.0 6 votes vote down vote up
@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    IonicStorageModule.forRoot(),
    AngularFireModule.initializeApp(environment.firebase),
    AngularFirestoreModule,
    AppRoutingModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
      }
    }),
    HttpClientModule,
    SharedModule.forRoot(),
    ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}
Example #21
Source File: translate-testing.module.ts    From mylog14 with GNU General Public License v3.0 6 votes vote down vote up
@NgModule({
  declarations: [
    TranslatePipeMock
  ],
  providers: [
    { provide: TranslateService, useClass: TranslateServiceStub },
    { provide: TranslatePipe, useClass: TranslatePipeMock },
  ],
  imports: [
    TranslateModule.forRoot({
      loader: { provide: TranslateLoader, useClass: FakeLoader },
    })
  ],
  exports: [
    TranslatePipeMock,
    TranslateModule
  ]
})
export class TranslateTestingModule {

}
Example #22
Source File: app.module.ts    From VIR with MIT License 6 votes vote down vote up
@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    HttpClientModule,
    CoreModule,
    SharedModule,
    HomeModule,
    DetailModule,
    AppRoutingModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient],
      },
    }),
  ],
  providers: [MetadataStore, DataStore, DataAnalyzer, FsUtil, Clock],
  bootstrap: [AppComponent],
})
export class AppModule {
}
Example #23
Source File: app.module.ts    From ionic-doctor-online with MIT License 6 votes vote down vote up
@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
      }
    }),
    SuperTabsModule.forRoot()
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    ShareServiceProvider,
    Storage
  ]
})
export class AppModule {}
Example #24
Source File: app.module.ts    From msfs-community-downloader with GNU Affero General Public License v3.0 6 votes vote down vote up
@NgModule({
    declarations: [AppComponent],
    imports: [
        BrowserModule,
        FormsModule,
        HttpClientModule,
        CoreModule,
        SharedModule,
        HomeModule,
        ListEditorModule,
        ImportModule,
        SettingsModule,
        AppRoutingModule,
        FontAwesomeModule,
        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                useFactory: HttpLoaderFactory,
                deps: [HttpClient]
            }
        })
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule {
}
Example #25
Source File: app.module.ts    From bitcoin-s-ts with MIT License 5 votes vote down vote up
@NgModule({
  declarations: [
    AppComponent,
    SplashComponent,
    AlertComponent,
    MoreInfoComponent,
    ConfirmationDialogComponent,
    ErrorDialogComponent,
    ConfigurationComponent,
    WalletBalanceComponent,
    ContractsComponent,
    EventsComponent,
    OffersComponent,
    ContractDetailComponent,
    EventDetailComponent,
    NewOfferComponent,
    BuildAcceptOfferComponent,
    AcceptOfferComponent,
    NewAddressDialogComponent,
    SendFundsDialogComponent,
    FeeRateDialogComponent,
    DlcFileComponent,
    DebugComponent,
    HeaderComponent,
    AboutComponent,
    NetworkComponent,
    LoginComponent,
    LogoutDialogComponent,
    AddressLabelComponent,
    ContactsComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    ReactiveFormsModule,
    HttpClientModule,
    TranslateModule.forRoot({
      defaultLanguage: 'en',
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
      }
    }),
    MaterialModule,
    NgChartsModule,
    QrCodeModule,
    ZXingScannerModule,
    AppRoutingModule,
  ],
  providers: [{
      provide: APP_INITIALIZER,
      useFactory: appInitializerFactory,
      deps: [TranslateService],
      multi: true
    }, {
      provide: HTTP_INTERCEPTORS,
      useClass: AuthInterceptor,
      multi: true
    }, {
      provide: HTTP_INTERCEPTORS,
      useClass: ErrorInterceptor,
      multi: true
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
Example #26
Source File: home.component.spec.ts    From ledge with Mozilla Public License 2.0 5 votes vote down vote up
describe('HomeComponent', () => {
  let component: HomeComponent;
  let fixture: ComponentFixture<HomeComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        SharedModule,
        PeriodicTableModule,
        RouterTestingModule,
        HttpClientTestingModule,
        TranslateModule.forRoot({
          loader: {
            provide: TranslateLoader,
            useClass: TranslateFakeLoader,
          },
        }),
      ],
      declarations: [HomeComponent],
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(HomeComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should update category', () => {
    const category = 'sourceMgr';

    component.setCurrentAtomCategory(category);

    expect(component.category).toBe(category);
  });

  it('should get data', () => {
    inject([HttpTestingController], (httpMock: HttpTestingController) => {
      component.ngAfterViewInit();

      const fisrt = httpMock.expectOne('./assets/periodic-table.json');
      const req = httpMock.expectOne(
        'https://api.github.com/repos/phodal/ledge/contributors'
      );
      expect(req.request.method).toEqual('GET');
      req.flush([]);

      httpMock.verify();
    });
  });
});
Example #27
Source File: app.module.ts    From dev-manager-desktop with Apache License 2.0 5 votes vote down vote up
@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    AddDeviceComponent,
    AppsComponent,
    FilesComponent,
    TerminalComponent,
    InfoComponent,
    KeyserverHintComponent,
    ExternalLinkDirective,
    ConnHintComponent,
    CrashesComponent,
    InstalledComponent,
    ChannelComponent,
    RenewScriptComponent,
    UpdateDetailsComponent,
    AttrsPermissionsPipe,
    TabComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    HttpClientModule,
    CoreModule,
    SharedModule,
    AppRoutingModule,
    ReactiveFormsModule,
    NgbModule,
    NgLetModule,
    NgxDatatableModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient]
      }
    }),
    AngularResizedEventModule,
    NgxFilesizeModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {
}
Example #28
Source File: translate-local-loader.ts    From taiga-front-next with GNU Affero General Public License v3.0 5 votes vote down vote up
StoryBookTranslationModule = () => {
  return TranslateModule.forRoot({
    loader: {provide: TranslateLoader, useClass: LocalTranslateLoader},
    defaultLanguage: 'en',
  });
}
Example #29
Source File: app.module.ts    From Elastos.Essentials.App with MIT License 5 votes vote down vote up
@NgModule({
  declarations: [
    AppComponent
  ],
  entryComponents: [
    AppComponent
  ],
  imports: [
    LauncherModule,

    /*
     * Sub-apps INIT (only - for bundle size / perf) modules
     */
    WalletInitModule,
    HiveManagerInitModule,
    IdentityInitModule,
    ContactsInitModule,
    DIDSessionsInitModule,
    ScannerInitModule,
    CRCouncilVotingInitModule,
    CRProposalVotingInitModule,
    SettingsInitModule,
    DPoSVotingInitModule,
    DPoSRegistrationInitModule,
    DeveloperToolsInitModule,

    /*
     * Generic modules
     */
    BrowserModule,
    BrowserAnimationsModule,
    //HttpClientModule,
    //SharedComponentsModule,
    IonicModule.forRoot({
      mode: 'ios',
      scrollAssist: false,
      scrollPadding: false,
      navAnimation: iosTransitionAnimation
    }),
    AppRoutingModule,
    //FormsModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (TranslateLoaderFactory)
      },
      missingTranslationHandler: { provide: MissingTranslationHandler, useClass: CustomMissingTranslationHandler },
    }),
    IonicStorageModule.forRoot({
      name: '__essentials.db',
      driverOrder: ['sqlite', 'indexeddb', 'localstorage', 'websql']
    }),
    BrowserAnimationsModule,
  ],
  providers,
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule { }