Skip to content

Loklify/laravel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Loklify for Laravel

Latest Version License

The official Laravel package for Loklify — the simple i18n platform for small teams.

Loklify replaces your local JSON translation files with a hosted API. Update translations on loklify.com and your Laravel app picks them up at runtime — no rebuild, no redeploy.

Requirements

  • PHP 8.2+
  • Laravel 11, 12 or 13

Installation

composer require loklify/laravel

Publish the config file:

php artisan vendor:publish --tag=loklify-config

Configuration

Add these variables to your .env file:

LOKLIFY_PROJECT_ID=your-project-uuid
LOKLIFY_CACHE_TTL=3600
Variable Description Default
LOKLIFY_PROJECT_ID Your project UUID (found in your Loklify dashboard)
LOKLIFY_CACHE_TTL Cache duration in seconds. Set to 0 to disable caching. 3600

The translation endpoint is public — no API token is required.

Config file

After publishing, the config is available at config/loklify.php:

return [
    'url'        => env('LOKLIFY_URL', 'https://api.loklify.com'),
    'project_id' => env('LOKLIFY_PROJECT_ID'),
    'token'      => env('LOKLIFY_TOKEN'),
    'cache_ttl'  => env('LOKLIFY_CACHE_TTL', 3600),
];

Usage

Once installed, Laravel's built-in translation system (__(), @lang, trans()) works with Loklify out of the box.

// In a controller
return view('welcome', [
    'greeting' => __('home.welcome'),
]);
{{-- In Blade --}}
<h1>{{ __('home.welcome') }}</h1>
<p>@lang('home.subtitle')</p>

Translations are fetched from your Loklify project and cached locally for the configured TTL.

How it works

The package registers a custom LoklifyLoader that wraps Laravel's default file-based translation loader:

  1. JSON translations (group *, namespace *) are loaded from the Loklify API
  2. All other translations (PHP files, vendor namespaces) fall through to the default Laravel loader
  3. ETag support — the loader sends If-None-Match headers. When translations haven't changed, the API returns 304 Not Modified and the local cache is reused without downloading data
  4. Caching — translations are cached locally. A freshness key prevents hitting the API on every request. After the TTL expires, the next request revalidates with the server

Cache flow

Request → Is fresh? (TTL not expired)
  ├── Yes → Return cached translations (no HTTP call)
  └── No → Send request with ETag
        ├── 304 Not Modified → Refresh TTL, return cached
        └── 200 OK → Store new translations + ETag, refresh TTL

Managing translations

Create and manage your translations on loklify.com:

  1. Create a project and add your languages
  2. Add translation keys (e.g. home.welcome, auth.login)
  3. Fill in translations — changes are live instantly
  4. Your Laravel app fetches them at runtime

Clearing the cache

To force-refresh translations:

php artisan cache:forget loklify.fresh.fr
php artisan cache:forget loklify.fresh.en

Or clear all cache:

php artisan cache:clear

Testing

composer test

License

MIT. See LICENSE for details.

Links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages