首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角MFE - WebPack5 -模块联盟- I18N平移

角MFE - WebPack5 -模块联盟- I18N平移
EN

Stack Overflow用户
提问于 2022-01-14 14:20:29
回答 1查看 1.3K关注 0票数 1

我们正在使用多个角度MFE项目(使用nx),在成功加载主机和远程模块并显示页面(通过路由)之后,下一步是翻译。

我有一个正在加载angular-i18next的共享翻译模块

代码语言:javascript
复制
import { CommonModule } from '@angular/common';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { I18NextModule } from 'angular-i18next';
import { I18N_PROVIDERS } from './i18next.config';

@NgModule({
  imports: [CommonModule, I18NextModule.forRoot()],
  providers: [I18N_PROVIDERS],
})
export class UtilTranslationsModule {

  // I setup the module providers for the root application.
  static forRoot(): ModuleWithProviders<UtilTranslationsModule> {

    return ({
      ngModule: UtilTranslationsModule,
      providers: [I18N_PROVIDERS],
    });

  }

使用i18Next选项:

代码语言:javascript
复制
import { APP_INITIALIZER, LOCALE_ID } from '@angular/core';

import { defaultInterpolationFormat, I18NextModule, I18NEXT_SERVICE, ITranslationService } from 'angular-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import HttpApi from 'i18next-http-backend';
import { Languages } from './languages.constant';

/*
 * Platform and Environment providers/directives/pipes
 */
const i18nextOptions = {
  whitelist: Object.values(Languages),
  fallbackLng: 'en',
  debug: false, // true, // set debug?
  returnEmptyString: false,
  ns: ['common', 'error', 'auth'],
  defaultNS: 'common',
  interpolation: {
    format: I18NextModule.interpolationFormat(defaultInterpolationFormat),
  },
  // backend plugin options
  backend: {
    loadPath: 'locales/{{lng}}/{{ns}}.json',
    addPath: 'locales/add/{{lng}}/{{ns}}',
    crossDomain: true,
  },
  // lang detection plugin options
  detection: {
    // order and from where user language should be detected
    order: ['localStorage', 'cookie'],

    // keys or params to lookup language from
    lookupCookie: 'lang',

    // cache user language on
    caches: ['localStorage', 'cookie'],

    // optional expire and domain for set cookie
    cookieMinutes: 10080, // 7 days
    cookieDomain: 'I18NEXT_LANG_COOKIE_DOMAIN',
  },
};

该模块在webpack sharedMappings.register(tsConfigPath, ['@tgc/translations'], workspaceRootPath);中共享。

文件通过i18next-http-backend库加载。主机正确加载翻译,但remote模块没有显示任何翻译,( 'auth:login.title' | i18nextCap)

我发现了一些类似的问题,但它只包含资产问题,比如angular mfe assets issue。翻译文件也作为project.json中的资产导出。

希望问题是清楚的,如果不是,我总是可以在这里添加一个示例代码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-14 16:51:04

我刚发现我必须让某个文件可以共享:

'angular-i18next': { singleton: true, strictVersion: true, requiredVersion: 'auto' },

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70712020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档