Getting started overview

Integrating Lokalise into a development workflow involves a sequence of steps, beginning with account creation and extending to making authenticated API requests. The core process focuses on obtaining necessary credentials—an API token and a project ID—which are fundamental for interacting with the Lokalise API to manage translation keys and project data. This guide outlines the initial setup, from signing up for a trial to executing a basic API call to retrieve project details or manage translation strings.

Lokalise offers a comprehensive API that supports various operations, including managing projects, languages, keys, and translations. Developers can choose to interact with the API directly using HTTP requests or leverage one of the Lokalise-provided SDKs for languages such as JavaScript, Python, Java, and Go. These SDKs abstract away the complexities of HTTP requests and authentication, providing language-specific methods for common tasks.

The developer experience with Lokalise is designed for continuous localization, often integrating with existing CI/CD pipelines and version control systems. Understanding the authentication mechanism and basic API structure is a prerequisite for building robust integrations that automate content globalization efforts.

Here's a quick reference for the initial setup steps:

Step What to Do Where
1. Sign Up Create a Lokalise account (14-day free trial available). Lokalise Pricing Page or homepage
2. Create Project Set up a new project in the Lokalise dashboard. Lokalise dashboard > Projects
3. Generate API Token Create a personal API token with appropriate permissions. Lokalise dashboard > Personal profile > API tokens
4. Get Project ID Locate the unique ID for your Lokalise project. Lokalise dashboard > Project settings > General
5. Make First Request Use your API token and project ID to make a test API call. Code editor / Terminal

Create an account and get keys

Account Registration

To begin using Lokalise, the first step is to register for an account. Lokalise offers a 14-day free trial, which provides full access to the platform's features for evaluation. The registration process typically involves providing an email address, setting a password, and confirming the email. After registration, users are directed to the Lokalise dashboard where new projects can be created.

Creating a Project

Once logged in, a project must be created to serve as a container for translation keys and languages. From the Lokalise dashboard, navigate to the "Projects" section and select "New project." When prompted, provide a project name and select a base language (e.g., English). Additional target languages can be added later. Each project is assigned a unique project ID, which is essential for API interactions.

Generating an API Token

API operations with Lokalise require authentication using an API token. This token acts as a credential to authorize requests. To generate a token:

  1. Navigate to your personal profile settings in the Lokalise dashboard.
  2. Find the "API tokens" or "Integrations" section.
  3. Click "Generate new token."
  4. Assign a descriptive name to the token (e.g., "My First API Integration").
  5. Crucially, select the necessary permissions for the token. For initial testing, it is advisable to grant read permissions for projects and keys. For write operations, additional permissions will be required. Lokalise provides detailed documentation on API token permissions.
  6. Copy the generated token immediately, as it will only be shown once. If lost, a new token must be generated.

This API token is sensitive and should be treated like a password. It should not be hardcoded directly into application source code but rather managed securely, for instance, through environment variables or a secure configuration management system. Best practices for API key management, as outlined by organizations like Google Cloud's authentication documentation, emphasize rotating keys and restricting their scope.

Obtaining the Project ID

Every action performed through the Lokalise API is scoped to a specific project. Therefore, the project ID is a mandatory parameter for most API endpoints. To find your project ID:

  1. From the Lokalise dashboard, select the project you created.
  2. Navigate to "Project settings."
  3. Under the "General" tab, the Project ID will be displayed prominently. Copy this ID for use in your API requests.

Your first request

With an API token and project ID, you can make your first authenticated request to the Lokalise API. This example demonstrates fetching project details using curl, a common command-line tool for making HTTP requests, and then shows a Python example using the Lokalise SDK.

Using curl (HTTP GET)

This curl command retrieves the details of your Lokalise project. Replace YOUR_API_TOKEN with your actual API token and YOUR_PROJECT_ID with your project's ID.

curl -X GET \
  "https://api.lokalise.com/api2/projects/YOUR_PROJECT_ID" \
  -H "X-Api-Token: YOUR_API_TOKEN"

A successful response will return a JSON object containing details about your project, including its name, creation date, and language configurations. An unsuccessful response might indicate an invalid API token, incorrect project ID, or insufficient permissions. Refer to the Lokalise API reference for expected response structures.

Using Python SDK (Example)

Lokalise provides SDKs for several programming languages, simplifying API interactions. This Python example uses the official Lokalise Python SDK to achieve the same result as the curl command.

First, install the Python SDK:

pip install python-lokalise-api

Then, use the following Python code:

from lokalise.api import Client

# Replace with your actual API token and project ID
api_token = "YOUR_API_TOKEN"
project_id = "YOUR_PROJECT_ID"

client = Client(api_token)

try:
    project = client.get_project(project_id)
    print(f"Project Name: {project.name}")
    print(f"Project ID: {project.project_id}")
    print(f"Base Language: {project.base_language.name}")
except Exception as e:
    print(f"Error fetching project: {e}")

This script initializes the Lokalise client with your API token and then calls the get_project method, passing your project ID. The SDK handles the underlying HTTP request and parses the JSON response into an object, making it easier to access project attributes.

Common next steps

After successfully making your first API call, consider these common next steps to further integrate Lokalise into your development workflow:

  • Add Translation Keys: Begin populating your project with translation keys. This can be done manually through the dashboard, via API, or by uploading existing translation files (e.g., .json, .po, .xliff). The Lokalise documentation on adding keys provides guidance.
  • Integrate with Version Control: Set up integrations with Git providers like GitHub, GitLab, or Bitbucket. This enables automated synchronization of translation files between your code repository and Lokalise, supporting continuous localization workflows.
  • Invite Team Members: Collaborate with translators, reviewers, and other developers by inviting them to your Lokalise project and assigning appropriate roles and permissions.
  • Configure Webhooks: Set up webhooks to receive real-time notifications about events in your Lokalise project, such as translation updates or new key additions. This can trigger automated processes in your CI/CD pipeline. Webhooks are a common pattern in API integrations, as documented by Twilio's webhook overview.
  • Explore SDKs: If you used curl for your first request, explore the available Lokalise SDKs for your preferred programming language. SDKs often streamline development by providing idiomatic interfaces for API operations.
  • Content Extraction and Import: Implement processes to extract translatable content from your application's source code and import it into Lokalise. Similarly, establish methods to export translated content from Lokalise and integrate it back into your build process.

Troubleshooting the first call

Encountering issues during the initial API call is common. Here are some troubleshooting tips:

  • Check API Token: Ensure the API token is correct and has not expired. Re-generate a new token if uncertain. Verify that the token has the necessary permissions (e.g., "Read projects" for fetching project details).
  • Verify Project ID: Double-check that the project ID used in the request matches the ID found in your Lokalise project settings. Project IDs are case-sensitive.
  • Inspect HTTP Status Codes: The HTTP status code in the API response provides crucial information.
    • 400 Bad Request: Often indicates malformed request body or incorrect parameters.
    • 401 Unauthorized: Typically means an invalid or missing API token.
    • 403 Forbidden: Suggests the API token lacks the required permissions for the requested action.
    • 404 Not Found: Could mean an incorrect endpoint URL or a non-existent project ID.
    • 5xx Server Error: Indicates an issue on the Lokalise server side; retry after some time.
  • Review Request Headers: Confirm that the X-Api-Token header is correctly set in your request.
  • Consult Lokalise Documentation: The Lokalise API reference provides detailed information on each endpoint, expected parameters, and potential error responses. Review the specific endpoint you are calling for any unique requirements.
  • Use a Tool for Inspection: For complex requests or debugging, consider using API testing tools like Postman or Insomnia, which provide graphical interfaces for constructing requests and inspecting responses.
  • SDK-specific Errors: If using an SDK, consult the SDK's documentation for specific error handling mechanisms and potential exceptions. The Python SDK, for instance, raises specific exceptions for API errors.