Search code examples
javascriptangularjsutf-8angular-translate

Angular translate UTF8 characters (pascalprecht.translate)


I am having problems with UTF8 characters while using SanitizeValueStrategy('sanitize'). I have to use it since the client is using the language files to edit texts and he might use tags like <b> or <i>...

I need to use only the json file for translations. The client won't touch the app code to change any text. JSON file:

{
    "H1": "Typy domů",
    "NAME": "Křestní"
}

The problems, thought, only occurs while using angular's interpolation:

<h1 translate>houseTypes.H1</h1>
Typy domů

I can use this method to put text inside of element's body, but this problems still occurs for attributes.

<input placeholder="'houseTypes.NAME'|translate"></h1>
K&#345;estn&#237;

The questions is:
How can I get UTF8 characters to be written correctly, while only using the JSON static file loader in interpolations, or any other way in attributes as is placeholder.


Solution

  • For anyone struggeling upon finding way how to make UTF-8 character normal even in {{interpolations}}, this is the way to do it:

    $translateProvider.useSanitizeValueStrategy('sanitizeParameters');
    

    This way the sanitize will be always made even in interpolations.