PHP code example of habr / bblslug

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;

$apiKey = getenv('BBLSLUG_GOOGLE_API_KEY') ?: getenv('GOOGLE_API_KEY');
if ($apiKey === false || $apiKey === '') {
    throw new \RuntimeException('Set BBLSLUG_GOOGLE_API_KEY or GOOGLE_API_KEY');
}

$result = Bblslug::translate(
    apiKey: $apiKey,
    format: 'json',
    modelKey: 'google:gemini-3.6-flash',
    text: '{"message":"Welcome to your workspace!","count":2}',
    context: 'Use formal address. Translate "workspace" as "Arbeitsbereich".',
    sourceLang: 'EN',
    targetLang: 'DE',
);

echo $result['result'];