hosteeka/laravel-lang

Use your Laravel translations in JavaScript.

dev-main 2025-03-21 21:44 UTC

This package is auto-updated.

Last update: 2025-07-21 22:27:58 UTC


README

This package is heavily inspired by Ziggy which enables you to use your Laravel routes in JavaScript.

Installation

You can install the package via composer:

composer require hosteeka/laravel-lang

Usage

Generate the JavaScript file with the translations:

php artisan lang:generate

This will create a resources/js/lang.js file with the translations:

// resources/js/lang.js

const Lang = {
  "defaultLocale": "es",
  "fallbackLocale": "en",
  "supportedLocales": {
    "en": "English",
    "es": "EspaƱol"
  },
  "translations": {
    "en": {
      "welcome": {
        "getting_started": "Let's get started :name"
      },
      "Laravel has an incredibly rich ecosystem.": "Laravel has an incredibly rich ecosystem."
    },
    "es": {
      "welcome": {
        "getting_started": "Empecemos :name"
      },
      "Laravel has an incredibly rich ecosystem.": "Laravel tiene un ecosistema increĆ­blemente rico."
    }
  }
}

To pass a custom path to generate the file, you can run the following command:

php artisan lang:generate public/js/lang.js