2

I am using angularJS translate directive to translate self employed to german like this

span(translate="translation_id")

and it gives me the following translation Selbstständig which is correct.

but when i did the same translation with translate service like below

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

But this time it gives me wrong translation Selbstständig. And the same problem is with translate filter.

The difference between both output is ä for ä. Why translate service and translate directive is showing different behaviour and how to resolve this issue.

chandradot99
  • 3,616
  • 6
  • 27
  • 45

1 Answers1

0

I don't know why angular translate directive and angular translate service behaves differently.

but below approach solved my problem.

when using angular translate service, i cannot use returned translations directly. First i have to decode the returned translations like this

$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;

I found the above approach here What's the right way to decode a string that has special HTML entities in it?

Community
  • 1
  • 1
chandradot99
  • 3,616
  • 6
  • 27
  • 45