Coder Social home page Coder Social logo

deeply's People

Contributors

chriskonnertz avatar fbuchlak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deeply's Issues

CurlHttpClient.php -> calllApi($url, array $payload, $method)

I'm doing my testing on a localhost machine using the demo_translate.php front end.
I've added a var_dump command at the end of the callApi function to help me understand the calls being made and how they are processed.

curl_close($curl);
var_dump($rawResponseData);
return $rawResponseData;

I am seeing a separate api call on every line input in the html text box. Even on empty lines.
I'm not a programmer by trade, not an api expert. I'm just wondering why so many calls like this? Can the entire text be sent as an array of lines with the 'to' and 'from' params set?

Update: At first it appeared like it might be something perhaps unintentional but appears the logic is as you have designed. I think just for my long term application I would try to split the text myself, if necessary and send the entire thing with one call.

Error in chriskonnertz/deeply/src/ChrisKonnertz/DeepLy/ResponseBag/TranslationBag.php

Note: not urgent, just trying it out.

$text = <<<EOS

The Center for American Progress puts it simply: “Americans work longer hours than workers in most other developed countries, including Japan, where there is a word, ‘karoshi’, for ‘death by overwork.’ The typical American middle-income family puts in an average of 11 more hours a week in 2006 than it did in 1979.” The end result is that we all live in a structurally toxic work world to use the title of an article written by Anne-Marie Slaughter, the author of “Unfinished Business: Women Men Work Family” published in 2015. The situation is bad for men and even worse for women. So what can we as individuals do about it without jeopardizing our job and reputation? Scott McDowell offers a useful starting point in a FastCompany article: Steps We Can All Take To Defy Our Culture Of Overwork:

If you are a boss, reduce your team’s hours.
Take your vacations.
Schedule free time.
Let your mind wander.
Stop talking how busy you are.

“In the past labor unions fought for worker sanity,” Scott McDowell adds. “In our current work culture we have to take individual responsibility for our well-being and for that of those around us. It’s time to alter the norms from within; our economy, health, productivity, and happiness depend on it.”
EOS;

$translatedText = $deepLy->translate($text, DeepLy::LANG_EN, DeepLy::LANG_FR);

Returns:

( ! ) Notice: Undefined offset: 0 in /var/www/html/libs/vendor/chriskonnertz/deeply/src/ChrisKonnertz/DeepLy/ResponseBag/TranslationBag.php on line 81
Call Stack

Time Memory Function Location

1 0.0006 367048 {main}( ) .../tryme.php:0
2 0.0103 1837440 ChrisKonnertz\DeepLy\DeepLy->translate( ) .../tryme.php:35
3 3.2932 1864856 ChrisKonnertz\DeepLy\ResponseBag\TranslationBag->getTranslation( ) .../DeepLy.php:239

( ! ) Notice: Trying to get property of non-object in /var/www/html/libs/vendor/chriskonnertz/deeply/src/ChrisKonnertz/DeepLy/ResponseBag/TranslationBag.php on line 87
Call Stack

Time Memory Function Location

1 0.0006 367048 {main}( ) .../tryme.php:0
2 0.0103 1837440 ChrisKonnertz\DeepLy\DeepLy->translate( ) .../tryme.php:35
3 3.2932 1864856 ChrisKonnertz\DeepLy\ResponseBag\TranslationBag->getTranslation( ) .../DeepLy.php:239
Le Center for American Progress le dit simplement:"Les Américains travaillent plus d'heures que les travailleurs dans la plupart des autres pays développés, y compris au Japon, où il y a un mot," karoshi ", pour" mort par surmenage "; la famille américaine typique à revenu moyen consacre en moyenne 11 heures de plus par semaine en 2006 qu'en 1979;" Le résultat final est que nous vivons tous dans un monde du travail structurellement toxique pour utiliser le titre d'un article écrit par Anne-Marie Sla ". La situation est mauvaise pour les hommes et pire encore pour les femmes. Que pouvons-nous donc faire, en tant qu'individus, pour y remédier sans mettre en péril notre travail et notre réputation? Prenez vos vacances. Prévoir du temps libre. Laisse ton esprit vagabonder. Arrête de dire à quel point tu es occupé. Dans le passé, les syndicats se sont battus pour la santé mentale des travailleurs ", ajoute Scott McDowell. Dans notre culture de travail actuelle, nous devons assumer la responsabilité individuelle de notre bien-être et de celui de ceux qui nous entourent. Il est temps de changer les normes de l'intérieur; notre économie, notre santé, notre productivité et notre bonheur en dépendent."

Open DeepL Translator Pro using authentication (without login)

Hello Chriskonnertz,

This could be a general question.

Our organization wanna open a translator for all employees, therefore they want to keep the translator link in the intranet.

So once the user opens the translator page, he/she must open the page with DeepL Pro (without explicit login) - how can we achieve that? is there any automatic OAuth API provided by DeepL?

Thanks in advance.

Best regards.

You can do an update!

You can do an update! the code of Deepl has changed you can review and see if it can still be used to make an update !! Please!!

Problem with translation

Hi,
I've a problem with the translations.
e.g if I translate the word "ciao" form italian to english, it still returns "ciao" . But if I translate "ciao amici miei" it's correct.

I'm using the latest version of your class.

crash on empty content

PHP Fatal error:  Uncaught exception 'ChrisKonnertz\DeepLy\ResponseBag\BagException' with message 'DeepLy API call resulted in a malformed result - beams array is empty in translation 0' in /home/developing/hn_bld/deepl/vendor/chriskonnertz/deeply/src/ChrisKonnertz/DeepLy/ResponseBag/TranslationBag.php:58
Stack trace:
#0 /home/developing/hn_bld/deepl/vendor/chriskonnertz/deeply/src/ChrisKonnertz/DeepLy/ResponseBag/AbstractBag.php(29): ChrisKonnertz\DeepLy\ResponseBag\TranslationBag->verifyResponseContent(Object(stdClass))
#1 /home/developing/hn_bld/deepl/vendor/chriskonnertz/deeply/src/ChrisKonnertz/DeepLy/DeepLy.php(279): ChrisKonnertz\DeepLy\ResponseBag\AbstractBag->__construct(Object(stdClass))
#2 /home/developing/hn_bld/deepl/vendor/chriskonnertz/deeply/src/ChrisKonnertz/DeepLy/DeepLy.php(299): ChrisKonnertz\DeepLy\DeepLy->requestTranslation('Kotlin/Native v...', 'PL', 'EN', false)
#3 /home/developing/hn_bld/bot.php(150): ChrisKonnertz\DeepLy\DeepLy->translate('Kotlin/Native v...', 'PL', 'EN')
#4 /home/developing/hn_bld/bo in /home/developing/hn_bld/deepl/vendor/chriskonnertz/deeply/src/ChrisKonnertz/DeepLy/ResponseBag/TranslationBag.php on line 58

Api request limit

Hi Chris, just to let you know, the API is currently limited. I still have to figure out if they put a hard limit on the absolute request count from an IP or are just limiting the number of requests within a certain timespan.

One should not currently rely on the API for production use.

Error message: Server side error during DeepLy API call: HTTP code 429, message: "{"jsonrpc": "2.0","error":{"code":1042901,"message":"Too many requests."}}"

[TODO] Ideas

Ideas / ToDO

  • Implement the new stuff from https://www.deepl.com/api-reference.html
  • Somehow extract the text from HTML page responses of the server and add it to the text of the exception that we throw (state: done for integrated cURL client)
  • Add framework (Symfony) support
  • More / better tests (for example for the translateFile() method)
  • Do not just throw a pretty generic exception when the result of sentence splitting is empty (Update: may be difficult since we get a malformed generic error response from the API)

Done

  • Keep line breaks
  • Check if the detectLanguage method makes two API calls. If so: Is this necessary? (Update: Not necessary)
  • Add Guzzle tests
  • Rewrite the broken "proposals" test
  • Add translateSentencesmethod that directly translates sentences without splliting a text into sentences -> this means the additional API call is no longer necessary
  • Add framework (Laravel) support
  • Create Guzzle based class that implements HttpClientInterface
  • Refactored the cURL HttpClient classes
  • Throw an exception if text length is exceeded (but make the check optional)
  • Implement some kind of ping method (most likely not possible before more is known about the API)
  • Refactor Deeply::splitText method --> create a separate bag class

Rejected

  • Use browser language and set it as target language in the demo script
  • Add caching (maybe...)

English text gets translated to french

When I call $deepLy->translate($text, 'EN', 'DE') deepLy returns french text when the original text ist aready english or mixed english/german (I don't do language checks, because sometimes we have mixed language texts.

Test case:

$deepLy = new ChrisKonnertz\DeepLy\DeepLy();
echo $deepLy->translate("Doors: 8pm Father Sky Mother Earth has released two monumental meditative albums since the beginning in autumn 2016. „Across the River of Time“ is an atmospheric journey through your own universe. Dark, intense and ecstatic: The Drone Doom Duo let’s you forget space and time. MAENTIS ist eine Doom Sludge Band aus Hildesheim. Das 2015 gegründete Quartett (Alexander Seidel & Jan Gibron – Gitarre, Björn Behrens – Bass, Andy Krüßel – Schlagzeug + Stimme) lässt massive Klangwände mit kalter, klirrender Psychedelik verschmelzen: der Zuhörer verfängt sich in einem Sog der transzendentalen Dunkelheit. Das Debut-Album I HAVE TASTED DEVIL’S BLOOD wird als eines der besten instrumentalen Sludge/Doom-Veröffentlichungen 2016 angesehen.",'EN','DE');

This also happens when I set source language to auto or EN.

And it also happens when I pass english strings with auto source or EN as source:

$deepLy = new ChrisKonnertz\DeepLy\DeepLy();
echo $deepLy->translate("Thunder and lightning",'EN');
echo $deepLy->translate("Thunder and lightning",'EN','EN');

This leaves the short source string in english, but doesnt work for the mixed longer text above:

echo $deepLy->translate("Thunder and lightning",'EN','DE');

Very complex your code

Nice but very granurality. over 10 class... 👎
Simply is Best.
One simply function.

$rta = translate('Hola todos, espero que hoy tengan un buen dia.'); print_r($rta);

`

function translate($text, $from='LANG_ES', $to='LANG_EN'){
$params =             ['lang'  => [ 'ser_preferred_langs' => ['LANG_ES', 'LANG_EN'], 'source_lang_user_selected' => 'LANG_ES', 'target_lang' => 'LANG_EN', ] ];
$params['jobs'][0] =  [ 'kind' => 'default', 'raw_en_sentence' => $text ];
$data = ['jsonrpc' => '2.0', 'method'  => 'LMT_handle_jobs', 'params'  => $params, 'id' => '2', ];
$data = json_encode($data);

$curl = curl_init('https://www.deepl.com/jsonrpc/');
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data))  );
$rawResponseData = curl_exec($curl);
$rawResponseData = json_decode($rawResponseData);
     
return $rawResponseData;    
}`

it does not work with some sentences(?)

Sometimes it simply do not translate the text,
for example
With this sentence: "Diatec Trentino-Cucine Lube Civitanova (Play Off, Finale - gara 1)"
from IT to EN it works perfectly.

but if I translate this one " Trentino Diatec-Tours Vb (Andata di Finale di 2017 CEV Cup)"
it simply return the exact same sentence not translated.

Deepl Pro with your lib

Hello,

I was using your lib with deepl but now I have purchased DeepL Pro, will your code work with pro ? And can you please tell me where I can use Auth Key in your code ?

Thanks.

What after getting 429 error.

Hello,

I am getting 429 request limit error. After how many time I can re-request for translation. When this error gone ?

Always get 'Too many request'

Hi i use your plugin to translate my website, and I love it!

From time to time i get an error "Too many request", if I used the API to much. After some time it worked again.

But since today, I get it from the start...

Do you think they changed something, so that this plugin is not working anymore?

Best
Beat

Too many requests.

I'm getting a mistake: {"jsonrpc": "2.0","error":{"code":1042902,"message":"Too many requests."}}
But there is a working option:

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://www2.deepl.com/jsonrpc');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"2.0\",\"method\": \"LMT_handle_jobs\",\"params\":{\"jobs\":[{\"kind\":\"default\",\"raw_en_sentence\":\"Too many requests.\",\"raw_en_context_before\":[],\"raw_en_context_after\":[],\"preferred_num_beams\":4}],\"lang\":{\"user_preferred_langs\":[\"DE\",\"ZH\",\"RU\",\"EN\"],\"source_lang_computed\":\"EN\",\"target_lang\":\"RU\"},\"priority\":1,\"commonJobParams\":{},\"timestamp\":1589020424674},\"id\":27440005}");
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');

$headers = array();
$headers[] = 'Authority: www2.deepl.com';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36';
$headers[] = 'Content-Type: text/plain';
$headers[] = 'Accept: */*';
$headers[] = 'Origin: https://www.deepl.com';
$headers[] = 'Sec-Fetch-Site: same-site';
$headers[] = 'Sec-Fetch-Mode: cors';
$headers[] = 'Sec-Fetch-Dest: empty';
$headers[] = 'Referer: https://www.deepl.com/translator';
$headers[] = 'Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6,zh;q=0.5';
$headers[] = 'Cookie: _ga=GA1.2.1530849196.1588933989; _gid=GA1.2.707299579.1588933989; LMTBID=067e4975-1add-4f13-8181-855b6f9d002c|6d2cbd1dedad11e5b2480e970569082c; _gat=1';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
print_r($result);

is there a way to fix the code?

Mod for miniAutoloader()

hi,

i add $class=str_replace('\', '/', $class); in your miniAutoloader-function ;)

kind regards,

andreas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.