Skip to content

Commit

Permalink
Merge pull request jefs42#1 from tabuna/patch-1
Browse files Browse the repository at this point in the history
Added types for syntax highlighting code examples
  • Loading branch information
jefs42 committed Apr 11, 2022
2 parents 7261a19 + 3ccd6eb commit 19fdc43
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ PHP Interface to the open source [LibreTranslate](https://github.com/LibreTransl
## Install
### Composer <small>(recommended)</small>

```
```bash
composer require jefs42/libretranslate
```
```
<?php

```php
require('vendor/autoload.php');

use Jefs42\LibreTranslate;

$translator = new LibreTranslate();
Expand All @@ -18,9 +19,9 @@ $translator = new LibreTranslate();
Download the LibreTranslate.php file from src/ directory and place somewhere in you project.

Include the file in your project:
```
<?php
```php
require_once("path/to/LibreTranslate.php");

use Jefs42\LibreTranslate;

$translator = new LibreTranslate();
Expand All @@ -31,7 +32,7 @@ By default, this class will try to connect to and use a local installation of th

Pass *host* and optionally *port*, *source* and/or *target* parameters to override defaults.

```
```php
// use locally installed LibreTranslate server on port 5000 with default language settings
$translator = new LibreTranslate();

Expand All @@ -46,14 +47,14 @@ $translator = new LibreTranslate(null, null, 'de', 'it');

### Set API Key
Depending on the server settings, you may need to provide a valid API key to make translation request.
```
```php
$translator->setApiKey('xxxxx-xxxxx-xxxxx');
```

### Set Default Languages
The default source and target languages are set by the server. You may override these settings when constructing the class, or as needed:

```
```php
// Set to translate from English to Swedish
$translator->setLanguages('en', 'sv');

Expand All @@ -69,14 +70,14 @@ Each translation function also supports specifying the languages to use when cal

### Detect Language
LibreTranslate will attempt to determine the language of the string passed to it.
```
```php
$lang = $translator->detect("mi nombre es jefs42");
// expected result: $lang = 'es'
```

### Translate Text
Translate a string of text. A server may or may not have a character limit set. For larger texts see Translate File.
```
```php
// translate text using current default source/target languages
$translatedText = $translator->translate("My name is jefs42");

Expand All @@ -89,7 +90,7 @@ $translatedText = $translator->translate("My name is jefs42", "en", "de");
Translate a file of text.

Check $translator->Settings(), current supported formats appear to be - .txt, .odt, .odp, .docx and .pptx
```
```php
// translate file using current default source/target languages
$translatedText = $translator->translateFile("/full/path/to/file.txt");

Expand All @@ -103,7 +104,7 @@ $translatedText = $translator->translateFile("/full/path/to/file.txt", "en", "it

### Suggest
Submit a suggested translation to the server.
```
```php
// Submit suggestion using current source/target language
$translator->suggest('My name is jefs42', 'Mi nombre es jefs42');

Expand All @@ -116,7 +117,7 @@ Sugesstions must be enabled on the LibreTranslate server.

### Get Available Languages
Get the list of languages available on the current server.
```
```php
$languages = $translator->Languages();
/*
Returns array of language codes/names:
Expand All @@ -128,7 +129,7 @@ Returns array of language codes/names:

### Check Server Settings
Get settings current server is running with.
```
```php
$settings = $translator->Settings();
/*
Returns array of settings and their current values:
Expand All @@ -151,7 +152,7 @@ If `ltmanage` is found in the local path then the following additonal functions

### listKeys
Will return an array of current keys and their request limits.
```
```php
$keys = $translator->listKeys();
/*
Returns array of current keys and limits:
Expand All @@ -164,7 +165,7 @@ Returns array of current keys and limits:
```
### addKey
Create a new key for local server with optional request limit.
```
```php
// create a new key limited to server defaults
$key = $translator->addKey();

Expand All @@ -179,7 +180,7 @@ Returns string of new key:

### removeKey
Delete an existing key from the available keys.
```
```php
try {
$translator->removeKey("xxxxx-xxxxx-xxxxx");
} catch (Exception $e) {
Expand Down

0 comments on commit 19fdc43

Please sign in to comment.