Skip to main content
Glama
GalvinGao

SimpleLocalize MCP Server

by GalvinGao

duplicate_translation

Copy translations from one key or namespace to another for creating similar keys or reorganizing translation structures.

Instructions

Duplicate translations from one key/namespace to another key/namespace.

This function copies all translations for a specific key (and optionally namespace) to another key (and optionally namespace). Useful for duplicating translations when creating similar keys or reorganizing translations.

Args: from_dict: Source dictionary with fields: - key (required): Source translation key - namespace (optional): Source namespace to_dict: Destination dictionary with fields: - key (required): Destination translation key - namespace (optional): Destination namespace

Returns: String message indicating success or failure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
from_dictYes
to_dictYes

Implementation Reference

  • main.py:207-313 (handler)
    The main handler function for the 'duplicate_translation' tool. It is decorated with @mcp.tool(), which registers it as an MCP tool. The function copies translations from a source key/namespace to a destination key/namespace by fetching existing translations via API, creating the destination key if necessary, and bulk-updating the translations using the SimpleLocalize API.
    @mcp.tool()
    async def duplicate_translation(from_dict: dict, to_dict: dict) -> str:
        """Duplicate translations from one key/namespace to another key/namespace.
        
        This function copies all translations for a specific key (and optionally namespace)
        to another key (and optionally namespace). Useful for duplicating translations
        when creating similar keys or reorganizing translations.
        
        Args:
            from_dict: Source dictionary with fields:
                - key (required): Source translation key
                - namespace (optional): Source namespace
            to_dict: Destination dictionary with fields:
                - key (required): Destination translation key
                - namespace (optional): Destination namespace
        
        Returns:
            String message indicating success or failure
        """
        # Validate input
        if not from_dict.get("key"):
            raise ValueError("Source dictionary must have a 'key' field")
        if not to_dict.get("key"):
            raise ValueError("Destination dictionary must have a 'key' field")
        
        source_key = from_dict["key"]
        source_namespace = from_dict.get("namespace", "")
        dest_key = to_dict["key"]
        dest_namespace = to_dict.get("namespace", "")
        
        try:
            # Step 1: Get all translations from the source
            result = await make_simplelocalize_request(
                "GET",
                "/api/v2/translations"
            )
            
            data = result.get("data", [])
            
            # Filter for translations matching the source key/namespace
            source_translations = []
            for item in data:
                key = item.get("key", "")
                namespace = item.get("namespace", "")
                language = item.get("language", "")
                text = item.get("text", "")
                
                # Check if this matches our source key/namespace
                if key == source_key and namespace == source_namespace and text:
                    source_translations.append({
                        "language": language,
                        "text": text
                    })
            
            if not source_translations:
                return f"No translations found for key '{source_key}'" + (f" in namespace '{source_namespace}'" if source_namespace else "")
            
            # Step 2: Create the destination key if it doesn't exist
            create_key_payload = {
                "key": dest_key
            }
            if dest_namespace:
                create_key_payload["namespace"] = dest_namespace
            
            # Try to create the key (will fail silently if it already exists)
            try:
                await make_simplelocalize_request(
                    "POST",
                    "/api/v1/translation-keys/bulk",
                    {"translationKeys": [create_key_payload]}
                )
            except SimpleLocalizeError:
                # Key might already exist, continue
                pass
            
            # Step 3: Copy all translations to the destination
            translations_to_update = []
            for trans in source_translations:
                update_payload = {
                    "key": dest_key,
                    "language": trans["language"],
                    "text": trans["text"]
                }
                if dest_namespace:
                    update_payload["namespace"] = dest_namespace
                translations_to_update.append(update_payload)
            
            # Update translations in bulk
            update_result = await make_simplelocalize_request(
                "PATCH",
                "/api/v2/translations/bulk",
                {"translations": translations_to_update}
            )
            
            if "failures" in update_result.get("data", {}):
                failures = update_result["data"]["failures"]
                if failures:
                    return f"Some translations failed to duplicate: {failures}"
            
            source_desc = f"'{source_key}'" + (f" (namespace: '{source_namespace}')" if source_namespace else "")
            dest_desc = f"'{dest_key}'" + (f" (namespace: '{dest_namespace}')" if dest_namespace else "")
            
            return f"Successfully duplicated {len(translations_to_update)} translation(s) from {source_desc} to {dest_desc}"
            
        except SimpleLocalizeError as e:
            return str(e)
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the tool 'copies all translations' and indicates it returns a success/failure message, but it lacks details on permissions, rate limits, error handling, or whether the operation is idempotent. The description adds some behavioral context but is incomplete for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose, followed by usage context and detailed parameter explanations. Every sentence adds value without redundancy, making it efficient and easy to parse for an AI agent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutation with nested objects) and lack of annotations or output schema, the description does a good job covering purpose, usage, and parameters. However, it could improve by detailing return values beyond 'string message' or addressing potential side effects, leaving some gaps in completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate fully. It does so by detailing the parameters: 'from_dict' and 'to_dict', each with required 'key' and optional 'namespace' fields, explaining their roles as source and destination. This adds significant meaning beyond the bare schema, fully documenting the two parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('duplicate', 'copies') and resources ('translations', 'key/namespace'). It distinguishes itself from siblings like 'create_translation_keys' or 'update_translations' by focusing on copying existing translations rather than creating new ones or modifying them directly.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context on when to use this tool ('useful for duplicating translations when creating similar keys or reorganizing translations'), but it does not explicitly state when not to use it or name alternatives among siblings. For example, it doesn't contrast with 'create_translation_keys' for new keys or 'update_translations' for modifications.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/GalvinGao/mcp-simplelocalize'

If you have feedback or need assistance with the MCP directory API, please join our Discord server