如何首先为 JSON 文件使用两个转换器,然后为 firestore 使用两个转换器? [英] How can I use two translators first for JSON file and second for firestore?

查看:22
本文介绍了如何首先为 JSON 文件使用两个转换器,然后为 firestore 使用两个转换器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSON 文件方法

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

JSON 文件加载器

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

AngularFirestore 方法

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

AngularFirestore 文件加载器

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

注意:我不能同时使用两个方法和 Loader 进行合并.

推荐答案

就像我已经在评论区回答你一样:

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.

但如果你需要类似的东西,你可以使用 MissingTranslationHandler 就像我在这里所做的那样:
https://github.com/Mr-Eluzive/angularfire-ngx-translate-example/tree/missing-translation-handler
您可以查看此分支和 master 之间的差异,以熟悉需要做什么才能使其正常工作.

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.

这篇关于如何首先为 JSON 文件使用两个转换器,然后为 firestore 使用两个转换器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆