Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Locale Anywhere Laravel Package

sloveniangooner/locale-anywhere

A Laravel package that lets you set and switch application locales from anywhere—routes, requests, sessions, or user preferences—with middleware and helpers to manage translations without tying locale detection to a single source.

View on GitHub
Deep Wiki
Context7

Getting Started

locale-anywhere is a Laravel Nova tool, so the integration path is the standard Nova tool flow — there is no separate service provider to wire up manually.

  1. Install the package

    composer require sloveniangooner/locale-anywhere
    

    If the package ships Nova frontend assets (most tools do), a php artisan vendor:publish tag and/or php artisan nova:publish may be required. Confirm against the package README — with 0 stars / 0 dependents, this is not a battle-tested package, so treat the install docs as authoritative over any assumption.

  2. Register the tool in app/Providers/NovaServiceProvider.php:

    use SlovenianGooner\LocaleAnywhere\LocaleAnywhere;
    
    public function tools()
    {
        return [
            new LocaleAnywhere,
        ];
    }
    
  3. Where to look first — open the tool's src/ directory and inspect:

    • The tool class (LocaleAnywhere.php) — its boot(), renderNavigation(), cards(), and any canSee/canRun callbacks.
    • routes/api.php — the endpoints the Vue frontend calls.
    • resources/js/ — the Vue component(s) if you need to extend or restyle the switcher.
  4. First use case — drop a locale switcher in the Nova UI and let an authenticated admin/nova user change the active application locale from any page in Nova, rather than only via a user profile page or a settings screen. This is the "anywhere" in the name: a global control rather than a per-resource field.

Implementation Patterns

Persisting the chosen locale. A tool that only flips App::setLocale() for the current request is useless in practice — the choice must survive navigation. Expect one of three persistence mechanisms, and verify which one the package uses before relying on it:

  • Session — simplest, but locale resets per browser tab/session and won't follow the user across devices.
  • User column — the robust pattern. If the package does not persist to users.locale, add a small wrapper:
    // In a listener or middleware
    $user = Auth::user();
    if ($user && $user->locale) {
        App::setLocale($user->locale);
    }
    
    and keep the users.locale column in sync from the tool's endpoint.
  • config('app.locale') fallback — the default when nothing is set.

Global middleware to apply the choice. Wrap the package's behavior in your own middleware so non-Nova routes (API, web) also honor the saved locale:

public function handle($request, Closure $next)
{
    $locale = session('locale', Auth::user()?->locale ?? config('app.locale'));
    if (in_array($locale, config('app.supported_locales', ['en']))) {
        App::setLocale($locale);
    }
    return $next($request);
}

This is where most developers will end up doing the real work — the tool is the UI affordance, not the whole localization pipeline.

Gate the tool. Nova tools are only as safe as their canSee / authorization. Lock it down:

new LocaleAnywhere,
// or via a policy / canSee if the tool supports it

For sensitive apps, restrict to administrators so editors don't accidentally switch the shared locale.

Pair with a translation package. If the goal is editing translations (not just viewing them in a chosen locale), this tool is only the entry point. Combine it with spatie/laravel-translatable or Nova's built-in translatable fields, and make sure the switcher and the translation editor agree on locale keys.

Daily workflow. For a developer/PM persona this usually looks like: an admin opens Nova → clicks the locale control in the header → the app (Nova + web) reloads in the chosen language → changes to content in the resource forms are written against that locale. Test this end-to-end, because the "anywhere" claim breaks the moment the locale isn't propagated to queued jobs, mailables, or cached fragments.

Gotchas and Tips

Verify maintenance status before committing. Score 0, 0 stars, 0 dependents. That is not a criticism of the code — it means there is almost no public usage to catch regressions, and you are effectively the first line of support. Pin the version in composer.json and budget time to read the source. If the tool's Vue assets were built against an older Nova major (e.g., Nova 3/4), they may fail to mount on Nova 4/5.

Nova asset versioning. After composer require, always run php artisan nova:publish (and clear nova-components caches). A blank tool or one that 404s on its JS bundle is almost always an unpublished/out-of-date asset build, not a bug in the tool.

Locale leakage across contexts. App::setLocale() is request-scoped but not automatically propagated to:

  • Queued jobs (ShouldQueue jobs need $this->locale set or App::setLocale in handle()).
  • Mailables and notifications (call ->locale($user->locale)).
  • Cached view fragments (cache keys must include the locale).
  • API responses generated outside the middleware chain (health checks, webhooks).

If the package only sets locale inside boot() or a Nova middleware, these contexts will silently fall back to config('app.locale').

Cache staleness. config('app.supported_locales') and config('app.locale') are cached by config:cache. Adding a new locale and seeing no change is a classic php artisan config:clear moment.

Debugging tips.

  • Check storage/logs/laravel.log for InvalidArgumentException: Locale [xx] is not supported — it usually means the tool's endpoint accepted a locale your App::setLocale allowlist doesn't.
  • Hit the tool's endpoint directly (e.g., GET /nova-vendor/locale-anywhere/...) with a valid Nova session to confirm the backend half works independently of the Vue layer.
  • Inspect session()->get('locale') and auth()->user()->locale after a switch to see where the choice actually landed.

Extension points. Because Nova tools expose a tool class and a Vue component, the lowest-friction customization is:

  • Overriding cards() / boot() in your own subclass.
  • Copying the Vue component into nova-components/ if you need different UI (e.g., a top-level bar vs. a dropdown).
  • Adding a canSee closure rather than modifying the vendor code — keeps composer update clean.

If the tool stalls, wrap it. Given the lack of ecosystem support, the pragmatic play is to treat this as UI sugar and implement locale persistence yourself (a users.locale column + global middleware + a simple Nova field or select on the user resource). You get the day-to-day benefit with a stack you fully control, and you can keep or drop the package later without a rewrite.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route