新一代平台已停用

装入模块的捆绑软件

您可以装入模块的捆绑软件以支持本地化和国际化。

过程

  1. 设置 TranslateModule 以使用 MultiTranslateHttpLoaderMultiTranslateHttpLoader 使用 HttpClient 来装入翻译,因此请在 TranslateModule之前导入 HttpClientModule
  2. MultiTranslateHttpLoader 采用转换文件配置的列表。 每个配置都有以下两个参数:prefix: string = "./assets/store-frontend/i18n/<moduleName>"suffix: string = ".json"
    注:
    • 确保在 BUNDLE_EXTENSIONS_HOME下创建文件夹 <moduleName>
    • 建议按以下格式创建 MultiTranslateHttpLoader 所需的配置。 在应用程序提供的功能部件模块中也采用了类似的方法。
      // Array of configurations required for the module declared in a class and exported. 
                              export class UserBundlesModule {
        static bundles: Array<any> = [
          {
            prefix: './assets/store-frontend/i18n/user/‘,
            suffix: '.json'
          }
      ];
      }
      
      /* Configure the custom MultiTranslateHttpLoader as an exported function. 
      If you are using any UI componets from SharedModule, you have to load the SharedModule bundles as well.
      In this case, you need to import SharedBundlesModule from SharedModule 
      and include them in your custom LoaderFactory function as shown in this code snippet. 
      If you are not using any UI components of SharedModule, then you need not include
      the SharedBundlesModule in the custom LoaderFactory. */
      
        export function UserBundlesModuleHttpLoaderFactory(http: HttpClient) 
      {
        const bundles = [];
        Array.prototype.push.apply(bundles, UserBundlesModule.bundles);
        Array.prototype.push.apply(bundles, SharedBundlesModule.bundles);
        return new MultiTranslateHttpLoader(http, bundles);
      }
      
      
      //  Initialize TranslateModule to use the custom LoaderFactory define earlier.
      TranslateModule.forRoot({
            loader: {
              provide: TranslateLoader,
              useFactory: UserBundlesModuleHttpLoaderFactory,
              deps: [HttpClient]
            }
       })
      
      
      //  Initialize the TranslateService for your custom module.
      export class UserModule {
        constructor(private translateService: TranslateService) {
      
      
          // Get language from appInfo or userInfo or resolvedLocale
          this.translateService.setDefaultLang(AppInfoService.getFallbackLanguage());
          this.translateService.use('en');
      
        }
      }