Download the PHP package goodcat/laravel-l10n without Composer

On this page you can find all versions of the php package goodcat/laravel-l10n. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-l10n

Laravel L10n

Latest Version on Packagist GitHub Tests Action Status

An opinionated Laravel package for app localization.

Quickstart

Get started with laravel-l10n in three steps.

  1. Download the package via Composer.

  2. Add the locale middlewares to your bootstrap/app.php file.

  3. Define localized routes using the lang() method.

That's it. You're all set to start using laravel-l10n.

Localized Routes

Defining Localized Routes

Use the lang() method to define which locales a route should support:

This will generate:

Route groups

To avoid repetitive language definitions on every single route, you can use Route::lang()->group():

All routes inside the group will inherit the locale definitions. A route can also extend the group's locales with its own lang() call — the locales are merged:

Translating Route URIs

Manage route translations in dedicated language files. The expected file structure is as follows:

Inside your routes.php file, map the original route URI to a translated slug:

If no translation is provided for a given locale, the original URI is used as-is.

[!NOTE] The key should be the route URI without the leading slash. For example, for Route::get('/example'), the key should be example.

Domain Translations

If your application uses domain-based routing, you can translate domains in the same routes.php language files. The key is the original domain string:

URL Generation

The package automatically replaces Laravel's default URL generator with LocalizedUrlGenerator, ensuring that the route() helper generates the correct URLs for the current locale without any extra configuration.

[!NOTE] If you need to use a custom URL generator, you can override it in your AppServiceProvider by aliasing your own implementation to the url service.

Using the route() and action() Helpers

Once the generator is registered, the route() helper will intelligently create URLs based on the current application locale.

The action() helper works the same way:

Locale Preference

This package provides a mechanism for automatically detecting a user's preferred language.

The SetPreferredLocale middleware is responsible for populating the preferred locale. It does this by checking a series of configurable preferred locale resolvers.

By default, the package checks the following sources in order:

  1. SessionLocale: Checks if a locale was set in the session.
  2. UserLocale: Checks if the authenticated user has a preferred locale (the user model must implement Laravel's Illuminate\Contracts\Translation\HasLocalePreference interface).
  3. BrowserLocale: Falls back to the browser's Accept-Language header.

Customizing Resolvers

You can customize the resolvers by setting the static property on the L10n class:

Creating a Custom Resolver

Implement the LocaleResolver interface to create your own resolver:

Then add it to the resolver chain:

Helpers

This package adds several helper methods to your Laravel application.

Application Helpers

Route Matching

Use L10n::is() to check if the current route matches a given pattern, regardless of the locale:

This is the localized equivalent of Route::is(). It resolves the canonical route behind any localized variant and delegates to Route::named().

Components

The package provides Blade components for common localization needs.

Alternate Hreflang Links

The package provides a Blade component that generates <link rel="alternate" hreflang="..."> tags following Google's guidelines for localized versions.

Add the component to the <head> of your layout:

For a route with es and it translations, this will render:

The component includes all localized variants, the fallback locale, and an x-default entry pointing to the canonical route. It renders nothing for routes without translations.

Locale Switcher

The package provides a Blade component that renders a <select> element for switching between available locales. When the user selects a different locale, the page reloads to the corresponding localized URL.

For a route with es and it translations, this will render:

The current locale is automatically selected. The component renders nothing for routes without translations.

You can pass any HTML attribute to the component:

Customizing the Templates

To customize the HTML output of the Blade components, publish the views:

This copies the templates to resources/views/vendor/l10n/components/. Each template documents the available variables in a docblock at the top of the file.

Localized Views

The application's view loader is configured to automatically search for a localized version of a view before falling back to the generic one.

When you render a view, the system follows a specific search order based on the current application locale.

This makes it straightforward to organize your views with a clean, language-based folder structure, like the one below.

The example.blade.php file in the root views folder can serve as your default template, while the localized versions (it/example.blade.php, es/example.blade.php) contain language-specific content or layouts.

JavaScript URL Generation

This package provides helper functions for generating localized URLs in your JavaScript/TypeScript frontend. Two stubs are available: one for Wayfinder and one for Ziggy. Given the following route definition:

Wayfinder

If you're using Wayfinder, publish the TypeScript helper:

[!NOTE] The route() helper only works with named routes, actions are not supported.

This creates a resources/js/l10n.ts file with the following exports:

Import the route helper and pass Wayfinder's generated route functions:

The locale is resolved in the following order:

  1. The lang parameter, if provided.
  2. The lang attribute of the <html lang="en"> element.
  3. The fallback locale.

Ziggy

If you're using Ziggy, publish the JavaScript helper:

This creates a resources/js/l10n.js file with a route function.

Use route() as a drop-in replacement for Ziggy's route() function:

The function automatically looks for a localized route by appending the locale to the route name (e.g., foo.es). If a localized route exists, it uses that; otherwise, it falls back to the original route name.

Configuration

To customize the package behavior, publish the configuration file:

Add Locale Prefix

By default, this package adds the locale prefix to every route generated via ->lang() (e.g. /es/ejemplo, /it/esempio). The original route (e.g. /example) always remains available as the canonical URL.

To disable prefixes, set add_locale_prefix to false in config/l10n.php. Routes will then use translated URIs without locale prefixes (e.g. /ejemplo instead of /es/ejemplo).

Route Caching

Localized routes are fully compatible with Laravel's route caching. When routes are cached, the package skips route generation at runtime (the localized variants are already included in the cache).


All versions of laravel-l10n with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^12.44.0|^13.0
illuminate/routing Version ^12.44.0|^13.0
illuminate/http Version ^12.44.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package goodcat/laravel-l10n contains the following files

Loading the files please wait ...