Skip to content

Replexica SDK (for JavaScript)

The Replexica SDK is a powerful tool for developers who need to integrate real-time AI-powered localization into their applications. It's designed to be simple to use, yet flexible enough to handle complex localization scenarios.

When to Use Replexica SDK

The SDK shines in scenarios where you need dynamic, context-aware translations:

  1. Chat applications: Translate messages on-the-fly.
  2. Email clients: Provide real-time translation of incoming emails.
  3. Comment systems: Localize user-generated content in real-time.
  4. Social media tools: Provide multilingual experiences for user posts and comments.

Getting Started

First, install the SDK:

bash
npm install @replexica/sdk

Then, initialize it in your code:

javascript
import { ReplexicaEngine } from '@replexica/sdk';

const replexica = new ReplexicaEngine({
  apiKey: 'your-api-key-here',
});

Core Functionality

The main method you'll use is localize:

javascript
const localizedContent = await replexica.localize(
  { greeting: 'Hello, world!' },
  { sourceLocale: 'en', targetLocale: 'es' }
);

This method takes your content, sends it to Replexica's AI, and returns the localized version.

Configuration Parameters

When initializing the SDK, you can customize several parameters:

  1. apiKey (required): Your unique identifier for accessing the Replexica API.

  2. batchSize (optional): Maximum number of items to send in a single API request. Defaults to 25. This helps manage API rate limits and network payload sizes.

  3. idealBatchItemSize (optional): Target word count for each batch. Defaults to 200. This optimizes API requests for efficiency and cost.

The SDK uses these parameters to chunk your content intelligently. It balances between making as few API calls as possible (for speed) and keeping each call's payload small (for reliability).

Under the Hood

While you don't need to know this to use the SDK, understanding how it works can help you use it more effectively:

  1. Content chunking: The SDK breaks your content into optimal chunks based on batchSize and idealBatchItemSize.

  2. Progress tracking: The SDK keeps track of processed chunks, enabling accurate progress reporting.

  3. Error handling: It manages API errors, retrying failed requests when appropriate.

  4. Response aggregation: After all chunks are processed, the SDK reassembles them into a single response.

This approach allows the SDK to handle large volumes of content efficiently, while providing a simple interface for developers.

Best Practices

  1. Reuse the ReplexicaEngine instance: Creating a new instance for every request is inefficient.

  2. Handle errors: While the SDK manages many error scenarios, your app should still have error handling in place.

  3. Use the progress callback for long-running tasks: This helps provide feedback to users during large translation jobs.

  4. Consider your content structure: The SDK works best with flat objects. If you have deeply nested content, consider flattening it before passing it to the SDK.

By leveraging the Replexica SDK, you can add powerful, AI-driven localization capabilities to your application with minimal effort. Whether you're building a chat app, a content platform, or any other multilingual software, Replexica SDK provides the tools you need to create seamless, real-time localization experiences.