Skip to main content
Glama
iamnotagentleman

Localizable XStrings MCP Server

translate_tool

Translate strings in iOS/macOS Xcode String Catalogs to target languages, returning translated keys for localization workflows.

Instructions

MCP tool to translate strings to target language and return translated keys.

Args:
    file_path (str): Path to the .xcstrings file
    target_language (str): Target language code

Returns:
    str: Translation result with translated keys or error message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
target_languageYes

Implementation Reference

  • The `translate_tool` function is the main handler for the MCP tool. It is registered via the `@mcp.tool()` decorator and implements the translation logic: validates the xcstrings file and language, fetches base language strings, translates them using `translate_strings`, handles skipped items, and formats the output.
    @mcp.tool()
    def translate_tool(file_path: str, target_language: str) -> str:
        """
        MCP tool to translate strings to target language and return translated keys.
    
        Args:
            file_path (str): Path to the .xcstrings file
            target_language (str): Target language code
    
        Returns:
            str: Translation result with translated keys or error message
        """
        try:
            if not validate_xcstrings_file(file_path):
                return f"Error: Invalid file path or not an .xcstrings file: {file_path}"
    
            if not validate_language_code(target_language):
                return f"Error: Invalid language code: {target_language}"
    
            # Get base keys
            base_keys = get_base_language_strings(file_path)
            if not base_keys:
                return "Error: No base language keys found"
    
            # Translate
            translated, skipped = translate_strings(base_keys, target_language)
            if not translated and not skipped:
                return "Error: Translation failed or returned no results"
    
            result = []
            if translated:
                result.append(f"Translated {len(translated)} strings to {target_language}:")
                for key, value in translated.items():
                    result.append(f"{key}: {value}")
            
            if skipped:
                result.append(f"\nSkipped {len(skipped)} strings:")
                for key, reason in skipped.items():
                    result.append(f"{key}: {reason}")
            
            return "\n".join(result)
        except Exception as e:
            return format_error_message(e, "Translation failed")
  • The `@mcp.tool()` decorator on line 76 registers the `translate_tool` function as an MCP tool.
    @mcp.tool()

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/iamnotagentleman/localizable-xcstrings-mcp'

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