Support Log in

19. Translation Memory API

Developer Guide
Prefer video? Watch the Lang Forge tutorials 9 short guides covering every feature Watch

PRO feature. REST endpoints for querying and managing Translation Memory. Every TM route checks both the WordPress capability and the current translation_memory entitlement, so a stale admin page or crafted REST request returns pro_required instead of reading, importing, exporting, populating, updating, or deleting entries after downgrade.

GET /langforge/v1/tm/suggest (PRO)

Get Translation Memory suggestions for a text segment. Returns both exact and fuzzy matches.

Permission: edit_posts Request:
bash
curl -s "https://example.com/wp-json/langforge/v1/tm/suggest?text=Welcome+to+our+site&from=en&to=ru" 
  -u "admin:XXXX XXXX XXXX XXXX XXXX XXXX"
Parameters:
ParameterTypeRequiredDescription
textstringYesSource text to match
fromstringYesSource language code
tostringYesTarget language code
Response (200):
json
[
    {
        "translated_text": "Добро пожаловать на наш сайт",
        "match_percentage": 100,
        "usage_count": 5,
        "type": "exact"
    },
    {
        "translated_text": "Добро пожаловать на наш портал",
        "match_percentage": 85,
        "usage_count": 2,
        "type": "fuzzy"
    }
]

GET /langforge/v1/tm/entries (PRO)

List Translation Memory entries with pagination and filtering.

Permission: manage_options Request:
bash
curl -s "https://example.com/wp-json/langforge/v1/tm/entries?from=en&to=ru&page=1&per_page=50" 
  -u "admin:XXXX XXXX XXXX XXXX XXXX XXXX"
Parameters:
ParameterTypeDefaultDescription
fromstring(all)Filter by source lang
tostring(all)Filter by target lang
pageinteger1Page number
per_pageinteger50Items per page (max 100)
Response (200):
json
{
    "entries": [
        {
            "id": 1,
            "source_text": "Welcome to our site",
            "translated_text": "Добро пожаловать на наш сайт",
            "source_lang": "en",
            "target_lang": "ru",
            "usage_count": 5,
            "created_at": "2025-01-15T10:30:00",
            "updated_at": "2025-03-20T14:22:00"
        }
    ],
    "total": 342,
    "pages": 7
}

POST /langforge/v1/tm/populate (PRO)

Populate Translation Memory from all existing post translations.

Permission: manage_options Request:
bash
curl -s -X POST "https://example.com/wp-json/langforge/v1/tm/populate" 
  -u "admin:XXXX XXXX XXXX XXXX XXXX XXXX"
Response (200):
json
{
    "success": true,
    "count": 342
}

DELETE /langforge/v1/tm/{id} (PRO)

Delete a single Translation Memory entry by its ID.

Permission: manage_options Request:
bash
curl -s -X DELETE "https://example.com/wp-json/langforge/v1/tm/15" 
  -u "admin:XXXX XXXX XXXX XXXX XXXX XXXX"
Response (200):
json
{
    "success": true,
    "message": "Entry deleted"
}

GET /langforge/v1/tm (PRO)

Paginated list of Translation Memory entries with optional full-text search and language-pair filtering. Mirrors the data shown on the Lang Forge → Translation Memory admin page.

Permission: manage_options Query parameters:
ParamTypeDefaultNotes
searchstring""Substring match against source_text OR translated_text
fromstring (ISO 639-1)""Filter by source language
tostring (ISO 639-1)""Filter by target language
pageint11-based page number
per_pageint25Clamped to 10..100
Response (200):
json
{
    "entries": [
        {
            "id": 12,
            "source_text": "Welcome to our site",
            "translated_text": "Добро пожаловать на наш сайт",
            "source_lang": "en",
            "target_lang": "ru",
            "usage_count": 7,
            "created_at": "2026-04-15 10:22:01",
            "updated_at": "2026-04-27 18:04:11"
        }
    ],
    "total": 412,
    "page": 1,
    "per_page": 25,
    "pages": 17
}

PUT /langforge/v1/tm/{id} (PRO)

Update the target text on a single TM pair. The source text is the unique key (source_hash + source_lang + target_lang) and cannot be edited from the API — that would orphan all existing TM lookups.

Permission: manage_options Body:
json
{
    "translated_text": "Добро пожаловать на наш обновлённый сайт"
}
Response (200):
json
{
    "success": true,
    "entry": {
        "id": 12,
        "source_text": "Welcome to our site",
        "translated_text": "Добро пожаловать на наш обновлённый сайт",
        "source_lang": "en",
        "target_lang": "ru",
        "usage_count": 7,
        "updated_at": "2026-04-28 09:42:18"
    }
}

Returns 400 with empty_target if the target is empty after stripping HTML, or 403 with pro_required if the license isn’t PRO.

POST /langforge/v1/tm/import-tmx (PRO)

Multipart upload of a TMX 1.4 file. The Worker parses every block and every (source → other) pair within it, hashes the source, and inserts pairs as new TM entries — or skips them when a same-source pair already exists in the same language combination.

Permission: manage_options Form fields:
  • tmx_file — file (.tmx or .xml, ≤ 10 MB)
  • overwrite1 to replace existing same-source pairs (default off — duplicates are skipped)
Response (200):
json
{
    "imported": 312,
    "skipped":  18,
    "errors":   0
}

GET /langforge/v1/tm/export-tmx (PRO)

Stream the entire memory as TMX 1.4 XML. Optional from / to query parameters scope the export to a single language pair.

Permission: manage_options Response headers:
text
Content-Type: application/xml; charset=UTF-8
Content-Disposition: attachment; filename="langforge-tm-en-ru-2026-04-28.tmx"
Body shape:
xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tmx SYSTEM "tmx14.dtd">
<tmx version="1.4">
  <header creationtool="LangForge" creationtoolversion="1.0.0"
          segtype="sentence" o-tmf="LangForge TM" adminlang="en"
          srclang="*all*" datatype="plaintext"
          creationdate="20260428T094218Z"/>
  <body>
    <tu>
      <tuv xml:lang="en"><seg>Welcome to our site</seg></tuv>
      <tuv xml:lang="ru"><seg>Добро пожаловать на наш сайт</seg></tuv>
    </tu>
    <!-- ... -->
  </body>
</tmx>

Forge AI Assistant Online

Hi! I'm the Lang Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs