错误"系统未定义(...)"国际化(I18N),angular-cli

Say*_*kib 10 angular

我试图用JiT和angular-cli 学习本教程.我在浏览器控制台中遇到以下错误,但终端没有错误来运行/构建应用程序.

未捕获的ReferenceError:系统未定义(...)

未捕获错误:找不到模块'./locale/messages.fr.xlf!text'.(...)

在此输入图像描述

我的代码在github https://github.com/sayedrakib/internationalization_project.git

我根据教程中的说明在根文件夹中添加了systemjs-text-plugin.js.文件结构 在此输入图像描述

我想我已经搞砸了一些文件中的文件路径,因为我觉得教程中的假定文件结构和angular-cli创建的文件结构不一样.

Mic*_*ick 1

我花了很长时间才弄清楚这一点!

如果您遵循文档,请更改此内容:

  1. 下载system.js,但它位于根目录 (/app) 中,并在 script 标记之前导入它。
  2. 在index.html中删除System.import('app')
  3. 将所有内容从 System 重命名为 SystemJS(index.html、i18n-provides.ts)

最后看起来像这样:

索引.html

<body>
  <app-root>Loading...</app-root>

  <script src="system.js"></script>
  <script>
    // Get the locale id somehow
    document.locale = 'es';

    // Map to the text plugin
    SystemJS.config({
      map: {
        text: 'systemjs-text-plugin.js'
      }
    });
  </script>
</body>
Run Code Online (Sandbox Code Playgroud)

i18n-providers.ts

export function getTranslationProviders(): Promise<Object[]> {
   [...]
}

declare let SystemJS: any;

function getTranslationsWithSystemJs(file: string) {
  return SystemJS.import(file + '!text'); // relies on text plugin
}
Run Code Online (Sandbox Code Playgroud)

我打开了GitHub Issue来更新文档。