home / skills / jeremylongshore / claude-code-plugins-plus-skills / lokalise-hello-world

This skill helps you set up a minimal Lokalise hello world example, list projects, create one, and add translations via API.

npx playbooks add skill jeremylongshore/claude-code-plugins-plus-skills --skill lokalise-hello-world

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
5.8 KB
---
name: lokalise-hello-world
description: |
  Create a minimal working Lokalise example.
  Use when starting a new Lokalise integration, testing your setup,
  or learning basic Lokalise API patterns.
  Trigger with phrases like "lokalise hello world", "lokalise example",
  "lokalise quick start", "simple lokalise code".
allowed-tools: Read, Write, Edit
version: 1.0.0
license: MIT
author: Jeremy Longshore <[email protected]>
---

# Lokalise Hello World

## Overview
Minimal working example demonstrating core Lokalise functionality: projects, keys, and translations.

## Prerequisites
- Completed `lokalise-install-auth` setup
- Valid API token configured
- At least one Lokalise project (or we'll create one)

## Instructions

### Step 1: Create Entry File
```bash
# Create project directory
mkdir lokalise-demo && cd lokalise-demo
npm init -y
npm install @lokalise/node-api dotenv

# Create main file
touch index.mjs
```

### Step 2: Initialize Client and List Projects
```typescript
// index.mjs
import "dotenv/config";
import { LokaliseApi } from "@lokalise/node-api";

const lokaliseApi = new LokaliseApi({
  apiKey: process.env.LOKALISE_API_TOKEN,
});

async function main() {
  // List all projects
  const projects = await lokaliseApi.projects().list();
  console.log("Your Lokalise Projects:");
  projects.items.forEach(p => {
    console.log(`  - ${p.name} (${p.project_id})`);
  });
}

main().catch(console.error);
```

### Step 3: Create a Project
```typescript
async function createProject() {
  const project = await lokaliseApi.projects().create({
    name: "My Demo Project",
    description: "Created via API",
    languages: [
      { lang_iso: "en", custom_iso: "" },  // English (base)
      { lang_iso: "es", custom_iso: "" },  // Spanish
      { lang_iso: "fr", custom_iso: "" },  // French
    ],
    base_lang_iso: "en",
  });

  console.log(`Created project: ${project.name}`);
  console.log(`Project ID: ${project.project_id}`);
  return project;
}
```

### Step 4: Add Translation Keys
```typescript
async function addKeys(projectId: string) {
  const keys = await lokaliseApi.keys().create({
    project_id: projectId,
    keys: [
      {
        key_name: "welcome.title",
        platforms: ["web"],
        translations: [
          { language_iso: "en", translation: "Welcome to our app!" },
          { language_iso: "es", translation: "Bienvenido a nuestra app!" },
          { language_iso: "fr", translation: "Bienvenue dans notre app!" },
        ],
      },
      {
        key_name: "welcome.subtitle",
        platforms: ["web"],
        translations: [
          { language_iso: "en", translation: "Get started today" },
        ],
      },
    ],
  });

  console.log(`Created ${keys.items.length} keys`);
  return keys;
}
```

### Step 5: Retrieve Translations
```typescript
async function getTranslations(projectId: string) {
  const translations = await lokaliseApi.translations().list({
    project_id: projectId,
    filter_lang_id: 640,  // English language ID
  });

  console.log("English translations:");
  translations.items.forEach(t => {
    console.log(`  ${t.key_id}: ${t.translation}`);
  });
}
```

## Output
- Working TypeScript/JavaScript file with Lokalise client
- Successfully listed, created projects
- Added translation keys with multiple languages
- Retrieved translations

## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| `401 Unauthorized` | Invalid token | Check LOKALISE_API_TOKEN |
| `400 Bad Request` | Invalid project/key params | Verify required fields |
| `404 Not Found` | Project doesn't exist | Check project_id |
| `429 Too Many Requests` | Rate limit hit | Wait 1 second, retry |

## Examples

### Complete Hello World Script
```typescript
import "dotenv/config";
import { LokaliseApi } from "@lokalise/node-api";

const lokaliseApi = new LokaliseApi({
  apiKey: process.env.LOKALISE_API_TOKEN,
});

async function helloLokalise() {
  // 1. List existing projects
  const projects = await lokaliseApi.projects().list();
  console.log(`Found ${projects.items.length} existing projects\n`);

  // 2. Create a demo project
  const project = await lokaliseApi.projects().create({
    name: `Demo ${Date.now()}`,
    languages: [
      { lang_iso: "en" },
      { lang_iso: "es" },
    ],
    base_lang_iso: "en",
  });
  console.log(`Created: ${project.name} (${project.project_id})\n`);

  // 3. Add a key with translations
  const keys = await lokaliseApi.keys().create({
    project_id: project.project_id,
    keys: [{
      key_name: "greeting",
      platforms: ["web"],
      translations: [
        { language_iso: "en", translation: "Hello, World!" },
        { language_iso: "es", translation: "Hola, Mundo!" },
      ],
    }],
  });
  console.log(`Added ${keys.items.length} key(s)\n`);

  // 4. Fetch the key back
  const fetchedKey = await lokaliseApi.keys().get(keys.items[0].key_id, {
    project_id: project.project_id,
  });
  console.log(`Key: ${fetchedKey.key_name.web}`);

  // 5. Clean up (optional)
  // await lokaliseApi.projects().delete(project.project_id);

  console.log("\nSuccess! Your Lokalise integration is working.");
}

helloLokalise().catch(console.error);
```

### Using CLI for Quick Test
```bash
# List projects
lokalise2 --token $LOKALISE_API_TOKEN project list

# Get project details
lokalise2 --token $LOKALISE_API_TOKEN project --project-id YOUR_PROJECT_ID

# List keys in a project
lokalise2 --token $LOKALISE_API_TOKEN key list --project-id YOUR_PROJECT_ID
```

## Resources
- [Lokalise API Reference](https://developers.lokalise.com/reference/lokalise-rest-api)
- [Projects API](https://developers.lokalise.com/reference/list-all-projects)
- [Keys API](https://developers.lokalise.com/reference/list-all-keys)
- [Translations API](https://developers.lokalise.com/reference/list-all-translations)

## Next Steps
Proceed to `lokalise-local-dev-loop` for development workflow setup.

Overview

This skill provides a minimal working Lokalise example to get an API integration up and running quickly. It demonstrates listing projects, creating a project, adding translation keys, and retrieving translations using the Lokalise Node client. Use it as a quick smoke test or learning reference for basic Lokalise API patterns.

How this skill works

The skill initializes a Lokalise client with an API token, lists existing projects, and optionally creates a demo project with languages. It then adds keys with translations, fetches translations or keys back, and prints concise results to the console. Errors like unauthorized tokens, invalid params, or rate limits are detected and mapped to simple remediation suggestions.

When to use it

  • Starting a new Lokalise integration or proof-of-concept
  • Verifying API token and client setup quickly
  • Learning basic Lokalise API patterns (projects, keys, translations)
  • Testing automation or CI jobs that need Lokalise access
  • Creating minimal reproducible examples for troubleshooting

Best practices

  • Store LOKALISE_API_TOKEN in environment variables or a secrets manager, not in source control
  • Start by listing projects to validate connectivity before creating resources
  • Use short-lived demo projects for testing and delete them afterward to avoid clutter
  • Handle common HTTP errors: 401 (check token), 400 (validate params), 404 (verify project_id), 429 (backoff and retry)
  • Limit language and key batches when testing to avoid hitting rate limits

Example use cases

  • Quick smoke test: run the hello world script to confirm token and API access
  • Create a demo project with English + Spanish and add a few sample keys for QA
  • Automated CI check that creates and fetches a key to ensure localization pipeline works
  • Tutorial or onboarding example for new engineers learning how to call Lokalise APIs
  • Script to reproduce and debug translation sync issues before integrating into a larger app

FAQ

What do I need before running the example?

You need a valid LOKALISE_API_TOKEN in your environment and the Lokalise Node client installed; optionally an existing project or permission to create one.

How do I avoid hitting rate limits during tests?

Keep test batches small, add a short delay on retries, and respect 429 responses by backing off one second or more before retrying.