Skip to content
Advertisement

LibreTranslate – different result with JS fetch and PHP curl

Hello I am trying to use this API with two different ways and I am not getting the same asnwer :

With Javascript :

JavaScript

The result I get here is :

JavaScript

Which is the expected result…

With PHP :

JavaScript

The result I get here is :

JavaScript

Which is not the expected one..

This problem happens in PHP when I try to translate multiple words, if I only translate one word (‘chat’ for example) here is what I get :

JavaScript

Also as you can see in the PHP function, the code where I try to set headers is commented because when I uncomment it this is what I get :

JavaScript

Thanks !

Advertisement

Answer

I fixed this by uting json_encode on the whole data instead of http_build_query, I also uncommented the header settings here is my working code :

JavaScript

and the response :

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement