Home/Blog/How to Use a Translation API with WordPress: Plugins, Code & Costs
WordPress Guide

How to Use a Translation API with WordPress: Plugins, Code & Costs

WordPress powers 43% of the web, but translating your site shouldn't cost a fortune. This guide covers three approaches: Loco Translate, TranslatePress, and direct API integration, with real cost comparisons.

Thomas van Leer· Content Manager, LangblyFebruary 13, 20269 min read

WordPress powers over 43% of all websites on the internet. If you're running a WordPress site and want to reach an international audience, you need translation. But the cost of translating a full website can add up quickly, especially if you're paying per-character rates to machine translation APIs.

This guide covers three practical ways to connect a translation API to your WordPress site: using the Loco Translate plugin, using TranslatePress, or building a direct API integration in your theme. We'll compare costs across providers and show you how to translate a typical WordPress site for a fraction of what most services charge.

Option 1: Langbly for Loco Translate

Loco Translate is one of the most popular WordPress translation plugins, with over 1 million active installations. It provides an in-dashboard editor for translating themes and plugins using standard .po and .mo files. Loco Translate also supports automatic machine translation, and you can connect it to Langbly for high-quality, context-aware translations at a fraction of the cost of Google Translate.

Setting up the Langbly plugin for Loco Translate

The Langbly for Loco Translate plugin adds Langbly as a machine translation provider inside Loco Translate's editor. Here's how to set it up:

Step 1: Install the Langbly for Loco Translate plugin from your WordPress dashboard, or upload the plugin files manually to /wp-content/plugins/langbly-for-loco-translate/.

Step 2: Add your Langbly API key to your wp-config.php file:

define( 'LANGBLY_API_KEY', 'your-api-key-here' );

Step 3: Open any translation file in Loco Translate's editor. You'll see a new Langbly option in the machine translation provider dropdown. Select it, and you can auto-translate individual strings or entire files with a single click.

How it works

When you click "Auto-translate" in Loco Translate, the plugin sends each untranslated string to the Langbly API. The API returns translations that are more natural and context-aware than traditional NMT engines. The translated strings are inserted directly into your .po file, ready for review and editing.

Because Loco Translate works with standard .po/.mo files, your translations are stored locally in your WordPress installation. There's no vendor lock-in and no external dependencies at runtime. The API is only used during the translation process itself.

When to use Loco Translate

  • Translating themes and plugins: Loco Translate is designed for string-based translation of WordPress themes and plugins. It's the best choice when your content is in .po files.
  • Developer workflows: If you're building custom themes or plugins and need to translate UI strings, Loco Translate integrates directly into your development workflow.
  • Budget-conscious sites: Because translations are stored locally, you only pay for the API call once per string. Subsequent page views use the cached translation at zero cost.

Option 2: Langbly for TranslatePress

TranslatePress takes a different approach to WordPress translation. Instead of translating individual strings in .po files, it translates entire pages visually. You browse your site in a side-by-side editor and translate content directly on the page, including dynamic content, menus, and widgets.

TranslatePress has over 400,000 active installations and supports automatic machine translation out of the box. With the Langbly integration, you can auto-translate your entire site using high-quality, context-aware translations.

Setting up Langbly with TranslatePress

Step 1: Install the Langbly for TranslatePress plugin alongside TranslatePress.

Step 2: Go to Settings → TranslatePress → Automatic Translation and enable automatic translation.

Step 3: Select Langbly as your machine translation engine and enter your API key.

Step 4: Set your translation languages under Settings → TranslatePress → General. Add the languages you want to translate into.

Once configured, TranslatePress will automatically translate pages as they are visited for the first time. Translations are cached in the database, so subsequent visits are served instantly without any API calls.

When to use TranslatePress

  • Full-page translation: TranslatePress translates everything visible on the page, including content from page builders, WooCommerce products, custom post types, and dynamic widgets.
  • Non-technical users: The visual editor makes it easy for content editors and site owners to review and adjust translations without touching any code.
  • WooCommerce stores: TranslatePress integrates deeply with WooCommerce, translating product pages, cart, checkout, and order confirmation pages.

Option 3: Direct API Integration in Your Theme

If you need more control over when and how translations happen, you can call the Langbly API directly from your WordPress theme or plugin using PHP. This is useful for custom post types, API-driven content, or headless WordPress setups.

Basic translation function

function langbly_translate( $text, $target_lang, $source_lang = 'en' ) {
    $api_key = defined( 'LANGBLY_API_KEY' ) ? LANGBLY_API_KEY : '';
    $url     = 'https://api.langbly.com/language/translate/v2';

    $response = wp_remote_post( $url, array(
        'headers' => array( 'Content-Type' => 'application/json' ),
        'body'    => wp_json_encode( array(
            'q'      => $text,
            'target' => $target_lang,
            'source' => $source_lang,
            'format' => 'text',
            'key'    => $api_key,
        ) ),
        'timeout' => 15,
    ) );

    if ( is_wp_error( $response ) ) {
        return $text; // Return original text on error
    }

    $body = json_decode( wp_remote_retrieve_body( $response ), true );
    return $body['data']['translations'][0]['translatedText'] ?? $text;
}

// Usage
echo langbly_translate( 'Hello, world!', 'de' );
// "Hallo, Welt!"

Translating with caching

To avoid calling the API on every page load, cache translations using WordPress transients:

function langbly_translate_cached( $text, $target_lang, $source_lang = 'en' ) {
    $cache_key = 'langbly_' . md5( $text . $target_lang . $source_lang );
    $cached    = get_transient( $cache_key );

    if ( false !== $cached ) {
        return $cached;
    }

    $translated = langbly_translate( $text, $target_lang, $source_lang );

    // Cache for 30 days
    set_transient( $cache_key, $translated, 30 * DAY_IN_SECONDS );

    return $translated;
}

Translating custom post meta

// Translate a product description stored in post meta
$description = get_post_meta( $post_id, 'product_description', true );
$translated  = langbly_translate_cached( $description, 'fr' );
echo $translated;

Batch translation for multiple fields

function langbly_translate_batch( $texts, $target_lang, $source_lang = 'en' ) {
    $api_key = defined( 'LANGBLY_API_KEY' ) ? LANGBLY_API_KEY : '';
    $url     = 'https://api.langbly.com/language/translate/v2';

    $response = wp_remote_post( $url, array(
        'headers' => array( 'Content-Type' => 'application/json' ),
        'body'    => wp_json_encode( array(
            'q'      => $texts,
            'target' => $target_lang,
            'source' => $source_lang,
            'format' => 'text',
            'key'    => $api_key,
        ) ),
        'timeout' => 30,
    ) );

    if ( is_wp_error( $response ) ) {
        return $texts;
    }

    $body         = json_decode( wp_remote_retrieve_body( $response ), true );
    $translations = $body['data']['translations'] ?? array();

    return array_map( function( $t ) {
        return $t['translatedText'];
    }, $translations );
}

// Usage - translate title, excerpt, and description in one call
$translated = langbly_translate_batch(
    array( $title, $excerpt, $description ),
    'es'
);

Comparing Translation Costs for WordPress

WordPress translation costs vary dramatically depending on which service and approach you use. Here's a comparison of the most common options:

ServicePricing model5M chars25M charsFree tier
Langbly Monthly plans $19/mo $69/mo 500K chars/mo
Google Translate API Pay-per-use $100/mo $500/mo 500K chars/mo
DeepL API Subscription + usage ~$125/mo ~$525/mo 500K chars/mo
WPML AI Credits Credit bundles ~$72 ~$360 None

WPML's automatic translation uses a credit system where you pre-purchase translation credits. While the per-word rate is competitive, there's no free tier and credits expire. With Langbly, you get predictable monthly pricing and a generous free tier to get started.

How Much Does WordPress Translation Cost?

Let's calculate a real-world example. Say you have a 50-page WordPress site that you want to translate into 5 languages.

Estimating character count:

  • Average page length: ~3,000 characters (roughly 500 words)
  • 50 pages x 3,000 characters = 150,000 characters per language
  • 5 languages x 150,000 = 750,000 characters total

Now let's compare what this costs across providers:

ProviderCost for 750K charsNotes
Langbly $0 Within the 500K free tier + overage. Or $19/mo Starter plan for comfortable headroom.
Google Translate API $5.00 500K free, then $20/1M for the remaining 250K
DeepL API Free $0 Within 500K free limit for first month. Overage requires paid plan at $25/mo base.
Human translator $1,500 – $3,750 At $0.10-$0.25 per word, 75,000 words across 5 languages

For a one-time translation of a small site, the cost difference between machine translation providers is minimal. But WordPress sites are rarely static. You'll be adding blog posts, updating pages, and translating new WooCommerce products on an ongoing basis. That's where monthly costs matter, and where Langbly's predictable pricing becomes an advantage.

A typical WordPress blog publishing 4 posts per week (roughly 4,000 characters each) in 5 languages uses about 3.2 million characters per month. At Google's rate, that's $64/month. With Langbly's Starter plan, it's $19/month.

Best Practices for WordPress Translation

Cache translations at every level

Whether you use Loco Translate, TranslatePress, or a custom integration, make sure translations are cached. Loco Translate stores translations in .mo files (fast binary lookups). TranslatePress caches in the database. For custom integrations, use WordPress transients or an object cache like Redis.

Translate URL slugs

For multilingual SEO, translate your URL slugs. Instead of /fr/my-english-slug, use /fr/mon-slug-francais. TranslatePress handles this automatically. With Loco Translate, you'll need a separate plugin like Polylang or WPML to manage translated slugs.

Add hreflang tags

Tell search engines about your translated pages by adding hreflang tags to your page headers. This prevents duplicate content issues and ensures Google shows the right language version to each user. Most multilingual plugins add these automatically, but verify they're present using Google Search Console.

Translate your SEO metadata

Don't forget to translate page titles, meta descriptions, and Open Graph tags. These are often stored separately from page content and may not be picked up by automatic translation tools. Check your SEO plugin settings (Yoast, Rank Math, etc.) to ensure metadata is translatable.

Review machine translations before publishing

Translations from Langbly are significantly more natural than NMT engines, but it's still good practice to review machine-translated content before publishing, especially for important pages like your homepage, landing pages, and legal pages. Use machine translation for the first draft, then have a native speaker review and refine.

Use HTML format for rich content

When translating WordPress content that includes formatting (bold, links, headings), send it as HTML with format: "html". The API preserves all HTML structure and only translates the text content. This is especially important for WooCommerce product descriptions that contain images, tables, or embedded media.

Which Approach Should You Choose?

ApproachBest forSkill levelWooCommerce
Loco Translate + Langbly Theme/plugin strings Beginner Partial
TranslatePress + Langbly Full site translation Beginner Full support
Custom PHP integration Headless/API-driven sites Developer Manual

For most WordPress site owners, TranslatePress + Langbly is the easiest path to a fully translated site. It handles the entire page, integrates with WooCommerce, and caches translations automatically. For theme and plugin developers who work with .po files, Loco Translate + Langbly fits naturally into the existing localization workflow.

Related Articles

WordPressTranslation APILoco TranslateTranslatePressPHPMultilingualPlugin

Start translating your WordPress site for free

Langbly gives you 500K free characters/month. Pair it with Loco Translate or TranslatePress to auto-translate your entire WordPress site at a fraction of the usual cost.