update_translations
Update multiple translations in bulk by specifying key, language, and text in a single request. Optional namespace inclusion supports organized localization workflows.
Instructions
Update translations in bulk with a single request.
This endpoint allows you to update multiple translations at once. You can update up to 100 translations in a single request. Each translation must specify the key, language, and text. Namespace is optional.
Args: translations: List of dictionaries containing translation information with fields: - key (required): Translation key - language (required): Language code - text (required): Translation text (max 65535 chars) - namespace (optional): Namespace for the key
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| translations | Yes |
Implementation Reference
- main.py:95-143 (handler)The handler function that implements the update_translations tool. It validates the input list of translation dictionaries, cleans and formats them, makes a bulk PATCH request to the SimpleLocalize API, and returns success or failure messages.async def update_translations(translations: List[dict]) -> str: """Update translations in bulk with a single request. This endpoint allows you to update multiple translations at once. You can update up to 100 translations in a single request. Each translation must specify the key, language, and text. Namespace is optional. Args: translations: List of dictionaries containing translation information with fields: - key (required): Translation key - language (required): Language code - text (required): Translation text (max 65535 chars) - namespace (optional): Namespace for the key """ # Validate and clean input cleaned_translations = [] for trans in translations: if not all(k in trans for k in ["key", "language", "text"]): raise ValueError("Each translation must have 'key', 'language', and 'text' fields") cleaned_trans = { "key": trans["key"], "language": trans["language"], "text": trans["text"] } # Only include namespace if it exists if "namespace" in trans: cleaned_trans["namespace"] = trans["namespace"] cleaned_translations.append(cleaned_trans) if len(cleaned_translations) > 100: raise ValueError("Maximum 100 translations allowed per request") try: result = await make_simplelocalize_request( "PATCH", "/api/v2/translations/bulk", {"translations": cleaned_translations} ) if "failures" in result.get("data", {}): failures = result["data"]["failures"] if failures: return f"Some translations failed to update: {failures}" return f"Successfully updated {len(cleaned_translations)} translations" except SimpleLocalizeError as e: return str(e)
- main.py:94-94 (registration)The @mcp.tool() decorator registers the update_translations function as an MCP tool.@mcp.tool()
- main.py:96-107 (schema)The docstring provides the input schema definition, detailing the structure of the 'translations' parameter as a list of dicts with required fields 'key', 'language', 'text' and optional 'namespace'."""Update translations in bulk with a single request. This endpoint allows you to update multiple translations at once. You can update up to 100 translations in a single request. Each translation must specify the key, language, and text. Namespace is optional. Args: translations: List of dictionaries containing translation information with fields: - key (required): Translation key - language (required): Language code - text (required): Translation text (max 65535 chars) - namespace (optional): Namespace for the key """
- main.py:19-43 (helper)Helper function used by update_translations to make authenticated HTTP requests to the SimpleLocalize API, handling POST, PATCH, GET methods and errors.async def make_simplelocalize_request(method: str, endpoint: str, json_data: dict | None = None) -> dict[str, Any]: """Make a request to the SimpleLocalize API with proper error handling.""" headers = { "X-SimpleLocalize-Token": SIMPLELOCALIZE_API_KEY, "Content-Type": "application/json" } url = f"{SIMPLELOCALIZE_API_BASE}{endpoint}" async with httpx.AsyncClient() as client: try: if method.upper() == "POST": response = await client.post(url, headers=headers, json=json_data, timeout=30.0) elif method.upper() == "PATCH": response = await client.patch(url, headers=headers, json=json_data, timeout=30.0) elif method.upper() == "GET": response = await client.get(url, headers=headers, timeout=30.0) else: raise ValueError(f"Unsupported HTTP method: {method}") response.raise_for_status() return response.json() except httpx.HTTPError as e: raise SimpleLocalizeError(f"SimpleLocalize API error: {str(e)}")