New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with html-entities in translation #1467
Comments
Can you list here example of html entities used? Can we enforce the non use of these, or are they useful? Are there some in English too? |
Yes, we can add a parameter to html_entity_decode(). We need the html entities because we output HTML to the browser, e.g.,
|
We don't use translations using entities to output html characters, atm. But in some languages entities are used for other special chars, too. see https://github.com/piwik/piwik/blob/master/lang/pt.php#L7 for example. Using html_entity_decode() should be the easiest way. Are all translation files in UTF-8, or are some using their own charset? |
Yes, there are other html entities in the non-English translations. The translation files should be UTF-8 -- I already have a script to fix these that I can run. |
+1 for your solution, a new parameter |
Actually, wouldn't this be considered a new format? Otherwise, I imaging some characters would still need to be escaped depending on the format. The easiest thing might be to use format=xml instead -- since the output is (generally) already html_entity_decode()'d -- and then on the client-side, convert a small number of specific exceptions: < > & "&. |
format=csv is also html_entity_decode()'d, and is more compact. The only tricky part is parsing multi-line fields (i.e., a quoted string that contains newlines). |
We are using JSON format as it can be directly used in javascript. adding a new format like json-decoded or so would do it, too. but is this decoding realy needed everywhere in the api? |
adding parameter to single api function sounds better, even though it will be useless for some formats. This can just be in the function comments to clarify. |
Sounds hackish. Could we decode by default when format=json? (Does that break the Flash chart data feed?) |
hm. good question. decoding by default for json format only would do it, too. Well, both ways are even possible and I already got solutions for both. |
Attachment: patch for /plugins/LanguagesManager/API.php |
I'm leaning towards the Json.php patch. Don't bother decoding the $key. It isn't passed by reference to the anonymous function, so decoding the $key wastes CPU cycles. |
Attachment: patch for /core/DataTable/Renderer/Json.php |
Oh, your right. I just fixed my patch. |
looks good to me |
(In [2480]) fixes #1467 always decode entities when format is json |
tests are failing. I'll leave it as an exercise to fix them :) Actually there is at least one failure that might be unexpected:
|
(In [2483]) fixes #1467 decode entities only for strings; fixed tests |
We got some trouble with the translations returned by the API.
In some languages the translations contain html-entities.
As we do not use a browser engine to output and there is no native javascript or Titanium function to decode entities, those entities are currently displayed in mobile application.
I guess the best way to fix this issue is to extend the language api function getTranslationsForLanguage with a optional second parameter that enables decoding entities before translations are returned.
The text was updated successfully, but these errors were encountered: