2016-08-03 51 views
2

,它给了我下面的翻译Selbstständig这是正确的。如何使用翻译服务,我使用angularJS翻译指令翻译<code>self employed</code>德国这样</p> <pre><code>span(translate="translation_id") </code></pre> <p>翻译过滤

,但是当我做了同样的翻译中包含

$translate("translation_id").then (translation) -> 
    $scope.translation = translation 

翻译服务,但这次它给了我错误的翻译Selbstst&#228;ndig。 同样的问题是翻译过滤器。

两个输出之间的差异是ä for &#228;。为什么翻译服务和翻译指令显示不同的行为以及如何解决此问题。

+0

什么是你的翻译的数组中的实际值进行解码? –

+0

@ S.Baggy实际值是Selbstständig –

回答

0

我不知道为什么angular translate指令和angular translate服务的行为有所不同。

但下面的方法解决了我的问题。

使用angular translate服务时,我无法直接使用返回的翻译。首先,我要返回的翻译这样

$translate("translation_id").then (translation) -> 
    $scope.translation = translation 

$scope.translation = decodeHtml($scope.translation) 

decodeHtml = (html) -> 
    var txt = document.createElement("textarea"); 
    txt.innerHTML = html; 
    return txt.value; 

我发现这里的上述方法What's the right way to decode a string that has special HTML entities in it?

相关问题