LearnSpeak uses Azure Translator for AI-powered batch translation of vocabulary words. This guide will help you set up your Azure Translator credentials.
- Azure account (free tier available)
- Access to Azure Portal
- Go to Azure Portal
- Click Create a resource
- Search for Translator
- Select Translator by Microsoft
- Click Create
Fill in the following details:
- Subscription: Choose your subscription
- Resource group: Create new or select existing
- Region: Choose closest region (e.g.,
eastus,westus2,eastasia) - Name: Give it a unique name (e.g.,
learnspeak-translator) - Pricing tier:
- Free (F0): 2M characters/month translation
- Standard (S1): Pay-as-you-go, $10 per 1M characters
Click Review + Create, then Create
- Once deployed, go to your Translator resource
- Click Keys and Endpoint in the left menu
- Copy one of the keys (KEY 1 or KEY 2)
- Note the Location/Region (e.g.,
eastus) - Note the Endpoint (usually
https://api.cognitive.microsofttranslator.com)
- Edit
backend/.envand set:AZURE_TRANSLATOR_KEY=your-key-from-step-3 AZURE_TRANSLATOR_REGION=eastus # Your region from step 3 AZURE_TRANSLATOR_ENDPOINT=https://api.cognitive.microsofttranslator.com TRANSLATOR_CACHE_ENABLED=true # Enable caching to reduce costs
-
Start the backend:
cd backend sh run.sh -
Log in to the frontend as a teacher
-
Go to any topic and click Bulk Add Words
-
Enter English words in the "Base Word" column
-
Click 🤖 AI Translate - translations should appear!
- 2 million characters per month free
- Suitable for development and small-scale usage
- ~20,000 typical word translations per month
- $10 per 1 million characters
- Pay only for what you use
- Suitable for production
- 1 word (average 5 characters): $0.00005
- 100 words: $0.005 (half a cent)
- 1000 words: $0.05 (5 cents)
- 10,000 words: $0.50 (50 cents)
With caching: Translations are cached, so repeated translations are free!
Azure Translator supports 100+ languages, including:
- English → Chinese (Traditional) (
en→zh-Hant) - English → Chinese (Simplified) (
en→zh-Hans) - Auto language detection available
en- Englishzh-Hant- Traditional Chinese (used in Hong Kong, Taiwan)zh-Hans- Simplified Chinese (used in Mainland China)yue- Cantonese (limited support)
Endpoint: POST /api/v1/translate
Request:
{
"text": "hello",
"fromLang": "en",
"toLang": "zh-Hant",
"suggestion": true
}Response:
{
"text": "hello",
"translation": "你好",
"detectedLanguage": "en",
"alternatives": ["哈囉", "您好"],
"cached": false
}Endpoint: POST /api/v1/translate/batch
Request:
{
"texts": ["apple", "banana", "orange"],
"fromLang": "en",
"toLang": "zh-Hant"
}Response:
{
"results": [
{
"text": "apple",
"translation": "蘋果",
"cached": false
},
{
"text": "banana",
"translation": "香蕉",
"cached": false
},
{
"text": "orange",
"translation": "橙",
"cached": true
}
],
"total": 3,
"cached": 1
}LearnSpeak caches translations to minimize API costs:
- Cache key: MD5(text + fromLang + toLang)
- Storage:
backend/uploads/translation-cache/[hash].json - Benefits:
- Same translation = instant response (no API call)
- Shared across all teachers
- Persists across restarts
- Check
AZURE_TRANSLATOR_KEYis set in.env - Verify the key is correct (no extra spaces)
- Restart the backend after changing
.env
- Verify
AZURE_TRANSLATOR_REGIONmatches your resource region - Check your Azure subscription is active
- Verify you haven't exceeded free tier limits
- Check Azure Portal for service status
- Check browser console for errors
- Verify the backend is running
- Check the language pair is supported
- Try with a simple test word first
- Azure Translator provides high-quality neural translations
- For educational content, consider:
- Reviewing AI translations before finalizing
- Using the alternative suggestions feature
- Providing context in longer phrases
- Navigate to any topic
- Click Quick Add Words or Bulk Add Words
- Enter English words in the "Base Word" column
- Select target language (e.g., "Cantonese (Traditional)")
- Click 🤖 AI Translate button
- Translations appear instantly (cached) or within 1-2 seconds
- Review and edit translations as needed
- Add optional audio, images, notes
- Click Create & Add Words
- Translate single words for vocabulary
- AI works best with common words and phrases
- Review translations for accuracy (especially idioms)
- Use romanization field for pronunciation guidance
- Leverage caching by translating common words first
- Translations per second: 10 requests/second (Free), 100 requests/second (Standard)
- Characters per request: 50,000 characters max
- Batch size: 100 items max per batch request
LearnSpeak's batch translation automatically handles these limits.
- Enable Caching: Always keep
TRANSLATOR_CACHE_ENABLED=true - Batch Processing: Use batch translate for multiple words (more efficient)
- Review Translations: AI is accurate but not perfect - review important content
- Monitor Usage: Check Azure Portal → Cost Management to track spending
- Free Tier First: Start with free tier, upgrade if needed
- Never commit
.envfile to git - Use environment variables in production
- Rotate keys periodically
- Use Azure Key Vault for production deployments
- Monitor usage for unexpected spikes (could indicate leaked keys)
Note: Azure Translator and Azure TTS are separate services. You need to set up both for full functionality:
- Azure TTS: Audio generation (see
docs/AZURE_TTS_SETUP.md) - Azure Translator: Text translation (this guide)