How can I use two translators first for JSON file

2019-04-17 00:27发布

JSON File Method

export function createTranslateLoader(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

JSON File Loader

 TranslateModule.forRoot({
          loader: {
              provide: TranslateLoader,
              useFactory: (createTranslateLoader),
              deps: [HttpClient]
          }
      }),

AngularFirestore Method

export function FirestoreTranslationsLoaderFactory(db: AngularFirestore) {
  return new FirestoreTransLoader(db);
}

AngularFirestore File Loader

TranslateModule.forRoot({
      loader: {
           provide: TranslateLoader,
           useFactory: FirestoreTranslationsLoaderFactory, 
           deps: [AngularFirestore]
        }
    }),

Note: I can't use two same time I try to merge in one method and Loader.

1条回答
混吃等死
2楼-- · 2019-04-17 00:35

Like I have already answered you in the comments section:

I think that storing theoretically one piece of data separately in two places is not the best idea.

But if you need something like that you can use MissingTranslationHandler like I have done here:
https://github.com/Mr-Eluzive/angularfire-ngx-translate-example/tree/missing-translation-handler
You can check out diffs between this branch and master to get familiar with what has to bo done to make it works.

查看更多
登录 后发表回答