gptrans
Version:
š GPTrans - The smarter AI-powered way to translate.
71 lines (55 loc) ⢠2.64 kB
JavaScript
import GPTrans from './index.js';
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function testImageTranslation() {
try {
console.log('š Starting Image Translation Test\n');
// Initialize GPTrans with Portuguese as target language
const gptrans = new GPTrans({
from: 'en-US',
target: 'pt-BR',
model: 'sonnet45'
});
// Test image path (you'll need to provide an actual image)
const testImagePath = path.join(__dirname, 'test-image.jpg');
// Check if test image exists
if (!fs.existsSync(testImagePath)) {
console.log('ā ļø Test image not found. Please create a test image at:', testImagePath);
console.log('You can use any image with text in it for testing.\n');
return;
}
console.log('šø Test image found:', testImagePath);
console.log('šÆ Target language: Portuguese (pt-BR)\n');
// First call - should return original image and start generation
console.log('š First call (should return original and start generation)...');
const result1 = await gptrans.translateImage(testImagePath);
console.log('Result 1:', result1);
console.log('');
// Wait a moment
console.log('ā³ Waiting 5 seconds before second call...\n');
await new Promise(resolve => setTimeout(resolve, 5000));
// Second call - check status
console.log('š Second call (checking if translation is ready)...');
const result2 = await gptrans.translateImage(testImagePath);
console.log('Result 2:', result2);
console.log('');
if (result2.isTranslated) {
console.log('ā
Translation completed! Translated image at:', result2.path);
} else {
console.log('ā³ Translation still generating... Check again later.');
console.log('Expected path:', path.join(path.dirname(testImagePath), 'pt-BR', path.basename(testImagePath)));
}
console.log('\nš Test completed!\n');
} catch (error) {
console.error('ā Error:', error.message);
if (error.message.includes('API Key') || error.message.includes('GEMINI_API_KEY')) {
console.error('\nš” Tip: Make sure you have GEMINI_API_KEY in your .env file');
console.error('You can get a free API key from: https://aistudio.google.com/apikey');
}
}
}
// Run the test
testImageTranslation();