1. Go to this page and download the library: Download habr/bblslug library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
habr / bblslug example snippets
use Bblslug\Bblslug;
$text = file_get_contents('input.html');
$result = Bblslug::translate(
apiKey: getenv('MODEL_API_KEY'), // API key for the chosen model
format: 'html', // 'text', 'html' of 'json'
modelKey: 'vendor:model', // Model identifier (e.g. deepl:free, openai:gpt-4o, etc.)
text: $text, // Source text to be translated
// optional:
// Additional context/prompt pass to model
context: 'Translate as a professional technical translator',
filters: ['url','html_code'], // List of placeholder filters
promptKey: 'translator', // which prompt template to use
proxy: getenv('BBLSLUG_PROXY'), // Optional proxy URI (http://..., socks5h://...)
sourceLang: 'DE', // Source language code (optional; autodetect if null)
targetLang: 'EN', // Target language code (optional; default from driver settings)
validate: false, // perform or skip syntax validation for container formats
variables: ['foo'=>'bar'], // model-specific overrides
verbose: true, // If true, returns debug request/response
);
echo $result['result'];
[
'original' => string, // Original input
'prepared' => string, // After placeholder filters
'result' => string, // Translated result
'httpStatus' => int, // HTTP status
'debugRequest' => string, // Request debug
'debugResponse' => string, // Response debug
'rawResponseBody' => string, // Response body
'consumed' => [ // Normalized usage metrics
'tokens' => [
'total' => int, // Total tokens consumed
'breakdown' => [ // Per-type breakdown
'prompt' => int, // Name depeds of model
'completion' => int, // Name depeds of model
],
],
// additional categories if supported by the model...
'lengths' => [ // Text length statistics
'original' => int, // - original text
'prepared' => int, // - after placeholder filters
'translated' => int, // - returned translated text
],
'filterStats' => [ // Placeholder stats
['filter'=>'url','count'=>3], …
],
]