Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 440
Akxe Avatar asked Jan 29 '16 15:01

Akxe


2 Answers

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.

like image 121
Akxe Avatar answered Oct 28 '22 23:10

Akxe


You have two options:

  1. Use the strategy sanitizeParameters which will only sanitize the dynamic parameters, but not the actual translation (template). If you have the translation under control (but not the dynamic values), this will work.
  2. Use the strategy escape (or escapeParameters) which does not use sanitization but escaping.

For me the problem was solved when i set SanitizeValueStrategy to null

$translateProvider.useSanitizeValueStrategy(null);
like image 30
Joel Joseph Avatar answered Oct 28 '22 22:10

Joel Joseph