2016-10-13 79 views
1

我目前正在研究如何在我的Angular2應用程序中實施國際化後,官方Angular2指南位於hereAngular2的國際化(i18n)不適用於不在根項目目錄中的templateUrls

我的應用程序的結構是這樣的:

my-angular2-app 
    | 
    +-- app 
    | | 
    | +-- myComponent 
    | | | 
    | | +-- myComponent.ts 
    | | +-- myComponent.html 

其中myComponent.ts看起來是這樣的:

import {Component} from '@angular/core'; 

@Component({ 
templateUrl: 'app/myComponent/myComponent.html', 
selector: 'my-component' 
}) 

export class MyComponent {} 

,並在那裏myComponent.html看起來是這樣的:

<h3 i18n="User welcome|An introduction header for this sample">Hello i18n!</h3> 

How曾經,我遇到一個錯誤,當我試圖通過

npm run i18n 

創建翻譯源文件通過應用程序的i18n搜索尋找國際化的標籤,它看起來像它更新文件路徑變量。然後,當它找到一個具有i18n標籤的組件時,它只會將組件中定義的templateUrl附加到filePath的末尾。

所以在我的情況下,i18n運行尋找i18n標籤。一旦最終達到myComponent的,目前的文件路徑變量似乎是:

C:/my-angular2-app/app/myComponent 

然後它發現在myComponent.html的國際化標籤和追加templateUrl在myComponent.ts的文件路徑變量導致文件路徑是集於:

C:/my-angular2-app/app/myComponent/app/myComponent/myComponent.html 

正因爲如此,我結束了一個錯誤,因爲顯然是不存在路徑:

Error: Compilation failed. Resource file not found: C:/my-angular2-app/app/myComponent/app/myComponent/myComponent.html 

我不知道是否我的思念或者它可能是Angular2國際化的錯誤,但任何幫助將不勝感激!

謝謝!

回答

0

我遇到了同樣的問題。我已經通過使用templateUrl參數中的相對路徑來解決它。以你爲例:

@Component({ 
templateUrl: './myComponent.html', 
selector: 'my-component' 
}) 
相關問題