← Back to Blog

How to Add Multilingual Support to Your App for Under $10/Month

You've built your app. It works. Users like it. But they're all in one language.

Adding multilingual support feels like a big project — and an expensive one. Google Translate API costs $20 per million characters. For a small app translating content into 5 languages, that's hundreds of dollars per month before you've even scaled.

But it doesn't have to be. In this tutorial, we'll add full multilingual support to an app for under $10/month using SocketsIO Translation API. We'll cover everything from signup to production code, with working examples in Python and JavaScript.

What We're Building

By the end of this tutorial, you'll have:

Prerequisites: Basic knowledge of Python or JavaScript, an HTTP client, and 10 minutes.

Step 1: Get Your API Key (2 Minutes)

  1. Go to socketsio.com
  2. Click "Get Started Free"
  3. Create an account — no credit card required
  4. Copy your API key from the dashboard

The free tier gives you 500,000 characters per month. That's enough to translate roughly 100,000 words — more than sufficient for development and testing.

For production, the Basic plan at $9/month gives you 5 million characters. That's 200,000 words of original content translated into 5 languages.

Step 2: Your First Translation (Python)

import requests

API_KEY = "your_api_key_here"
API_URL = "https://api.socketsio.com/v2/translate"

def translate(text, target_lang, source_lang="en"):
    """Translate text to the target language."""
    response = requests.post(
        API_URL,
        headers={
            "Content-Type": "application/json",
            "x-api-key": API_KEY
        },
        json={
            "q": text,
            "source": source_lang,
            "target": target_lang,
            "format": "text"
        }
    )
    response.raise_for_status()
    return response.json()["data"]["translations"][0]["translatedText"]

# Try it
print(translate("Hello, world!", "es"))  # → ¡Hola, mundo!
print(translate("Hello, world!", "ja"))  # → こんにちは世界!
print(translate("Hello, world!", "fr"))  # → Bonjour le monde !

That's it. Three lines of setup, one function call. You're translating.

Step 3: Your First Translation (JavaScript / Node.js)

const axios = require('axios');

const API_KEY = 'your_api_key_here';
const API_URL = 'https://api.socketsio.com/v2/translate';

async function translate(text, targetLang, sourceLang = 'en') {
  const response = await axios.post(API_URL, {
    q: text,
    source: sourceLang,
    target: targetLang,
    format: 'text'
  }, {
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': API_KEY
    }
  });
  return response.data.data.translations[0].translatedText;
}

// Try it
(async () => {
  console.log(await translate('Hello, world!', 'es'));
  console.log(await translate('Hello, world!', 'ja'));
  console.log(await translate('Hello, world!', 'fr'));
})();

Step 4: Batch Translation for Efficiency

Translating one string at a time works, but it's inefficient for real apps. Here's how to translate multiple strings in a single request:

Python — Batch Translation

def translate_batch(texts, target_lang, source_lang="en"):
    """Translate multiple texts in a single API call."""
    response = requests.post(
        API_URL,
        headers={
            "Content-Type": "application/json",
            "x-api-key": API_KEY
        },
        json={
            "q": texts,  # Pass a list of strings
            "source": source_lang,
            "target": target_lang,
            "format": "text"
        }
    )
    response.raise_for_status()
    return [t["translatedText"] for t in response.json()["data"]["translations"]]

# Translate your entire UI in one call
ui_strings = [
    "Welcome back",
    "Settings",
    "Log out",
    "Your cart is empty",
    "Continue shopping"
]

spanish = translate_batch(ui_strings, "es")
print(spanish)

Step 5: Translating HTML Content

If your app has rich text content, you need to translate while preserving HTML tags. SocketsIO handles this with the format parameter:

def translate_html(html_content, target_lang, source_lang="en"):
    """Translate HTML while preserving tags."""
    response = requests.post(
        API_URL,
        headers={
            "Content-Type": "application/json",
            "x-api-key": API_KEY
        },
        json={
            "q": html_content,
            "source": source_lang,
            "target": target_lang,
            "format": "html"  # Preserves HTML tags
        }
    )
    response.raise_for_status()
    return response.json()["data"]["translations"][0]["translatedText"]

# Example
html = '<p>Welcome to our <strong>online store</strong>.</p>'
result = translate_html(html, "de")
print(result)
# → <p>Willkommen in unserem <strong>Online-Shop</strong>.</p>

Step 6: Build a Production Translation Client

For production use, here's a clean helper class with error handling and local caching:

Python — Production-Ready Client

import requests
import json
import hashlib
from pathlib import Path

class Translator:
    def __init__(self, api_key, cache_dir="./translation_cache"):
        self.api_key = api_key
        self.api_url = "https://api.socketsio.com/v2/translate"
        self.cache_dir = Path(cache_dir)
        self.cache_dir.mkdir(exist_ok=True)
        self._memory_cache = {}

    def _cache_key(self, text, source, target):
        raw = f"{source}:{target}:{text}"
        return hashlib.md5(raw.encode()).hexdigest()

    def translate(self, text, target_lang, source_lang="en", format="text"):
        # Check local cache
        key = self._cache_key(text, source_lang, target_lang)
        if key in self._memory_cache:
            return self._memory_cache[key]

        # Call API (server also caches via Redis)
        response = requests.post(
            self.api_url,
            headers={
                "Content-Type": "application/json",
                "x-api-key": self.api_key
            },
            json={
                "q": text,
                "source": source_lang,
                "target": target_lang,
                "format": format
            },
            timeout=10
        )
        response.raise_for_status()
        result = response.json()["data"]["translations"][0]["translatedText"]
        self._memory_cache[key] = result
        return result

# Usage
translator = Translator(api_key="your_api_key_here")
print(translator.translate("Hello world", "es"))

Step 7: Real Cost Calculation for Your App

Personal Blog (5 languages)

10 posts/month × 1,500 words × 5 chars/word × 5 languages = 3,750,000 chars
Cost: Basic plan at $9/month (covers 5M chars)

E-commerce Store (3 languages)

500 products × 200 chars + 1,000 reviews × 300 chars = 400,000 chars
× 3 languages = 1,200,000 chars/month
Cost: Free tier ($0) or Basic plan ($9) with headroom

SaaS App with User Content (8 languages)

5,000 messages × 200 chars × 8 languages = 8,000,000 chars/month
Cost: ~$9-18/month with SocketsIO
vs $160/month with Google Translate
Savings: $1,812/year

Step 8: Common Integration Patterns

Pattern 1: Translate on Write, Serve from Database

The most cost-efficient pattern. Translate content when it's created, store translations in your database, and serve them directly.

# When a user creates a post
def create_post(content, author_id):
    post = db.posts.create(content=content, author_id=author_id, lang="en")

    # Translate to supported languages in background
    target_langs = ["es", "fr", "de", "ja"]
    for lang in target_langs:
        translated = translator.translate(content, lang)
        db.translations.create(post_id=post.id, lang=lang, content=translated)

    return post

# When serving content
def get_post(post_id, lang="en"):
    if lang == "en":
        return db.posts.get(post_id)
    return db.translations.get(post_id=post_id, lang=lang)

Cost impact: You only pay for translation once per piece of content. Reads are free.

Pattern 2: JSON Locale File Generation

For static UI strings, generate locale files at build time:

import json

en_strings = {
    "nav.home": "Home",
    "nav.about": "About Us",
    "btn.submit": "Submit",
    "msg.welcome": "Welcome back, {name}!"
}

def generate_locale_file(source_strings, target_lang):
    texts = list(source_strings.values())
    keys = list(source_strings.keys())
    translations = translator.translate_batch(texts, target_lang)
    locale = dict(zip(keys, translations))

    with open(f"./locales/{target_lang}.json", "w") as f:
        json.dump(locale, f, ensure_ascii=False, indent=2)

# Generate all locale files
for lang in ["es", "fr", "de", "ja", "ko", "zh"]:
    generate_locale_file(en_strings, lang)

Tips to Minimize Cost

  1. Use batch requests. Translate multiple strings in one API call instead of one at a time.
  2. Implement local caching. Combined with SocketsIO's server-side Redis cache, you minimize duplicate API calls.
  3. Translate on write, not read. Store translations in your database. Serving from your own DB is free.
  4. Generate static locale files at build time. UI strings don't change often.
  5. Skip translation for universal strings. Numbers, URLs, email addresses, brand names.

Wrapping Up

Adding multilingual support to your app doesn't require an enterprise budget. With SocketsIO Translation API:

The API is Google Translate v2 compatible, so if you've used Google's translation API before, you already know how to use SocketsIO. Same format, same parameters, same response structure. Just a different URL and a much smaller bill.

Start with the free tier. No credit card. No commitment. Just translations.

Ready to make your app multilingual?

Get your free API key and start translating in 30 seconds.

Get Your Free API Key →
← Back to Blog