Lara CLI: Setup & Intallation

CLI Installation

  1. Prerequisites

Before installing, ensure you have the following requirements met:

  • Node.js: version 16.0.0 or higher.
  • npm: usually bundled with Node.js.
🚧

Note

This project uses pnpm. If you don't have it installed, run: npm install -g pnpm. Verify the installation with pnpm -v before proceeding with the following commands.

  1. Global Installation

For most use cases, we recommend installing the CLI globally. This allows you to use the lara command from any directory on your system.

pnpm install -g @translated/lara-cli
  1. Local Installation

If you prefer to keep dependencies project-specific, you can install it as a development dependency:

pnpm install --save-dev @translated/lara-cli

When installed locally, you can trigger the CLI using npx:

npx lara --version

Local Development Setup

  1. Clone the repository
git clone https://github.com/translated/lara-cli.git
  1. Navigate to the cloned repository
cd lara-cli
  1. Install dependencies and build

Note: This project uses pnpm. If you don't have it installed, run: npm install -g pnpm. Verify the installation with pnpm -v before proceeding with the following commands.

pnpm install
pnpm run build
  1. Setup pnpm global bin directory (first time only)
pnpm setup

This command configures your shell to add the pnpm global bin directory to your PATH. After running it, you'll see output similar to:

Appended new lines to /Users/<username>/.zshrc

Next configuration changes were made:
export PNPM_HOME="/Users/<username>/Library/pnpm"
case ":$PATH:" in
  *":$PNPM_HOME:"*) ;;
  *) export PATH="$PNPM_HOME:$PATH" ;;
esac

Add these lines to your shell profile (.zshrc, .bashrc, etc.) or restart your terminal to apply the changes. This ensures you can run globally installed pnpm packages.

  1. Link globally
pnpm link --global

Note: If you experience an error like ERR_PNPM_NO_GLOBAL_BIN_DIR, you may need to manually copy and paste the lines added by pnpm setup into your shell profile. After doing so, restart your terminal or source your profile file, and you should be able to proceed.

After running this command, the project will be successfully linked to the pnpm global library. You should see a response similar to:

/Users/username/Library/pnpm/global/5:
+ lara-cli version <- ../../../../Projects/translated/lara-cli
  1. Installation Complete - Use anywhere

Now that Lara Dev is installed globally, you can use it from any directory on your system:

# Get help with available commands
lara-cli --help

# Initialize a new Lara project
lara-cli init --help

# Translate your localization files
lara-cli translate --help

Note: After making changes to the source code, run pnpm run build to update the global command.

Setting Up Your Project

Add Your Credentials to .env

Create a .env file (or add the following lines to an existing .env) in the project where you want to run translations.

💡 Tip: If you don't have API keys yet, visit Lara's API key documentation.

LARA_ACCESS_KEY_ID=<YOUR_ACCESS_KEY_ID>
LARA_ACCESS_KEY_SECRET=<YOUR_ACCESS_KEY_SECRET>

Replace the placeholders with your actual credentials.

🔑 Need to update credentials? If your API keys expire or need updating, run lara-cli init --reset-credentials to safely update them in your .env file.

Initialize Your Project

In your project directory, run:

lara-cli init

This will start the interactive initialization process.

The CLI will automatically detect your localization directories and target locales from your existing project files, then guide you through a few questions. These will be used to generate the configuration file: lara.yaml.