1

我将我的应用程序的源代码从 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..”,但这对我没有帮助。

有没有人有任何想法?

谢谢!

4

1 回答 1

0

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

于 2021-06-01T11:49:58.790 回答