DeepLcom / deepl-php

Official PHP library for the DeepL language translation API.
MIT License
202 stars 23 forks source link

instaling libreries without composer #31

Closed jcparejo closed 1 year ago

jcparejo commented 1 year ago

Hi. I have problem with composer and deepl libraries.

It is posible to install without composer ?

Where are the files and a simple example in php for translate deepl using a frre api

best regards

JanEbbing commented 1 year ago

Hi, we don't currently support using this library without composer. To do so, you simply need to download the files from this repo (Code -> Download ZIP -> extract that, or git clone the repository), and copy them into a vendor directory in your PHP project. Then you just need to require_once('vendor/deepl-php/src/Translator.php'); all the files in src and you're good to go. I'm working on an init.php which makes it easier to use the library without composer, but I still need to test it better.

Also see this related StackOverflow question for how to deal with dependencies etc.

jcparejo commented 1 year ago

Thank you

jcparejo commented 1 year ago

I did it but it does work. I see a .composer on my host and i have include the vendor /deepl-php with all files It show a 500 error do i have to change any file ? i am new on it and i am a bit lost

JanEbbing commented 1 year ago

How did you install the dependencies of the project and when do you get which error exactly?

jcparejo commented 1 year ago

I hace use FTP to upload in .composer/vendor/dewpl-php

JanEbbing commented 1 year ago

Like I said, you will need to install the dependencies as well (and their dependencies), which is what composer would do for you. Check the stackoverflow link. The 500 error you get when you visit the website is just what your webserver serves to an end user, you would need to check your server's logs to get a stacktrace and see which error occurs server-side.

jcparejo commented 1 year ago

I have install deepl with compoer -> composer require deeplcom/deepl-php

later i have created a php file with

$authKey = " My deelp key"; // Replace with your key $translator = new \DeepL\Translator($authKey);

$result = $translator->translateText('Hello, world!', null, 'fr'); echo $result->text; // Bonjour, le monde!

But it does work

later, i have create a folder deepl2 in root createing the composer project and works.

i don know if i have to include any line more

JanEbbing commented 1 year ago

Hi, sorry, could you clearly state

  1. what commands you run (I understood composer require deeplcom/deepl-php, create script.php in a folder with this structure:
├── yourproject
│   ├── vendor
│   │   ├── deepl-php/...
│   ├── script.php

with the contents above, then run php script.php )

  1. Which exact error messages you get if something doesn't work (just copy/paste)
  2. Which parts work (you wrote works twice but I assume at least 1 of them is supposed to say "does not work")

Otherwise I have to guess. Make sure you changed the value in the line $authKey = " My deelp key"; // Replace with your key to your DeepL API key.

Also, if you run it like I described above you need to load the library, the easiest way is to use the autoloader provided by composer, see the docs.

If you set up your project like I outlined above, it would simply be the following (again, with your API key)

require __DIR__ . '/vendor/autoload.php';
$authKey = " My deelp key"; // Replace with your key
$translator = new \DeepL\Translator($authKey);

$result = $translator->translateText('Hello, world!', null, 'fr');
echo $result->text; // Bonjour, le monde!
jcparejo commented 1 year ago

Hi JanEbbing

I have resolved it just adding the require link to the fólder whete IS the vendor files

Thank you for your time