PHP code example of michalskoula / codeigniter-ai-translation

1. Go to this page and download the library: Download michalskoula/codeigniter-ai-translation 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/ */

    

michalskoula / codeigniter-ai-translation example snippets



MichalSkoula\CodeIgniterAITranslation\Provider;

$translator = new MichalSkoula\CodeIgniterAITranslation\Translator(
    Provider::CLAUDE,         // provider: claude or openai
    'claude-sonnet-4-6',      // model name
    'your-api-key',           // API key for Claude or OpenAI
    'cs',                     // source language (need to match you directory name)
    'en',                     // target language (need to match you directory name; will be created automatically)
    'application/language',   // path to your language files
    3                         // CodeIgniter version (3 - default, 4)
);

// Or change it later
$translator->setProvider(Provider::OPENAI);
$translator->setModel('gpt-4o');

// if $file is null, if will translate all files in the directory
$result = $translator->translate($file);

echo "Translation process completed." . PHP_EOL;
echo "Total files processed: " . $result->getProcessed() . PHP_EOL;
echo "Total items translated: " . $result->getTranslated() . PHP_EOL;
echo "Total items failed: " . $result->getFailed() . PHP_EOL;
if ($result->isError()) {
    echo 'Error: ' . $result->getErrorMessage() . PHP_EOL;
}