2016-11-16 55 views
2

在我的應用程序中,我使用angular-translate來翻譯我的應用程序。現在我開始使用angular-ui-notification,並且卡住了。嘗試翻譯來自angular-ui-notification的消息時,角度轉換不起作用。 角翻譯使用這種語法鑑於angular-ui-notification和翻譯消息

{{ badRequestServerError | translate}} 

翻譯這裏是我的控制器通知

if (response.status == 400) { 
    Notification.error({message: '{{ badRequestServerError | translate}}', positionY: 'bottom', positionX: 'right'}); 
     }; 

但這不工作。當我打開瀏覽器我allways得到這

{{ badRequestServerError | translate}}

在我看來我嘗試使用不帶引號,但仍然沒有。 在github angular-ui-notification我找不到解釋的地方。

回答

0

如果$scope.badRequestServerError值是翻譯鍵,你可以注入$filter到控制器中,然後:

Notification.error({message: $filter('translate')($scope.badRequestServerError), positionY: 'bottom', positionX: 'right'}); 

或者,如果您正在使用的服務器響應的狀態代碼和badRequestServerError已經是翻譯的關鍵,你可以這樣設置:

Notification.error({message: $filter('translate')('badRequestServerError'), positionY: 'bottom', positionX: 'right'}); 
+0

很好的解決方案,但是如何在這種情況下在我的translate.js文件中定義翻譯文本。例如,我有英文,並添加badRequestServerError:「不良要求等」,對於克羅地亞,我添加badRequestServerError:「kriv zahtjev」。如何處理這個問題,如何在所選語言的「$ scope」消息上更改語言設置? – Arter

+0

如果您使用'angular-translate',它不會自行翻譯文本。您應該首先定義一對關鍵值。例如:'{'BAD_REQUEST_ENG':'錯誤的請求','BAD_REQUEST_CRO':'kriv zahtjev'}',並且讓你的服務器只發送密鑰。查看'angular-translate' [網站](https://angular-translate.github.io/)的「工作原理」部分。 – user3632710

+0

thnx,我定義了這個,這個工作(我有一點問題,英文)...我給你的​​plunker不工作的版本,因爲我的應用程序有很多很多的部分...這裏是鏈接translate.js文件和我的控制器https://plnkr.co/edit/4ITHsiDCtie1I1c5noHI?p=catalogue thanke you – Arter