【问题标题】:After update to Angular12 i18n localizing dosnt work anymore更新到 Angular 12 i18n 本地化后不再起作用
【发布时间】:2021-05-21 06:59:09
【问题描述】:

我将我的应用程序的源代码从 Angular6 更新到了 Angular12 - 是的,我错过了它以更频繁地更新它。

现在 IU 语言不再变化。我正在使用 i18n。似乎 html 没有应用翻译。因为我仍然可以从 API 加载 XLF 文件,但翻译不会显示在 UI 中。

在 Angular 应用程序中,我必须在 main.ts 中遵循代码:

const httpClient: HttpClient = injector.get(HttpClient);
httpClient.get(localizationUrl, {responseType: "text"})
    .subscribe(res => {
            const translations = res;
            let locale = "de-DE";
            let respCulture = /(?:(?:target-language)="([\w-]+)")/i.exec(translations);
            if (respCulture)
                locale = respCulture[1];
            platformBrowserDynamic().bootstrapModule(AppModule, {
                // missingTranslation: MissingTranslationStrategy.Warning,
                providers: [
                    {provide: LOCALE_ID, useValue: locale},
                    {provide: TRANSLATIONS, useValue: translations},
                    {provide: TRANSLATIONS_FORMAT, useValue: "xlf"}
                ]
            });
        },
        error => console.log(error));

语言环境始终是“de”,我也尝试了“de-DE”,但它不会改变行为。 在我的 html 中,我像这样使用 i18n:

<h3 i18n="@@settings-tab-header">You will receive your incoming invoices automatically in PDF format.</h3>

我试图找到一个问题,将我的代码与 https://angular.io/guide/i18n 进行比较,但我找不到任何东西。 我还尝试评论“提供:LOCALE_ID..”和“提供:TRANSLATIONS_FORMAT..”,但这对我没有帮助。

有人有什么想法吗?

谢谢!

【问题讨论】:

    标签: internationalization translation angular12


    【解决方案1】:

    我现在通过在应用程序中提供翻译解决了这个问题。因此,我失去了在没有应用部署的情况下更改翻译的好处。

    【讨论】:

      猜你喜欢
      • 2021-08-23
      • 1970-01-01
      • 2019-11-27
      • 2021-08-03
      • 2021-12-03
      • 2014-12-14
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      相关资源
      最近更新 更多