Download the PHP package outerweb/localization without Composer

On this page you can find all versions of the php package outerweb/localization. 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 localization

Localization

Latest Version on Packagist Total Downloads

This package adds multi-language support to your Laravel application:

Installation

You can install the package via composer:

Add the Outerweb\Localization\Http\Middleware\SetLocale middleware to the web middleware group in app/Http/Kernel.php: This will automatically set the locale for each request by going through the following steps:

  1. Check if the locale is set in the URL (e.g. http://example.com/en)
  2. Check if the locale is set in a cookie
  3. Check for a matching locale in the preferred languages of the user's browser
  4. Use the fallback locale

You can publish the config file with:

This is the contents of the published config file:

Usage

Defining routes

Define the routes you want to localize like this:

This will then generate the home route for each locale you have defined in the supported_locales config value.

For example, if you have defined en and nl as supported locales, the following routes will be generated:

You can also define a fallback route that will redirect to the localized route:

Translating route segments

You can translate each route segment by adding it to the configured translations file in the lang directory.

For example, if you defined a route /about-us and you support the locales en and nl, you can add this to the configured translations files:

In lang/en/routes.php:

In lang/nl/routes.php:

This will then generate the following routes:

Generating localized URLs

When using localized routes, you cannot use the route() helper to generate URLs. Instead, you can use the localizedRoute() helper:

As you can see above, this one takes the same parameters as the route() helper.

Getting the localized routes for the current route

You can get the localized routes for the current route like this:

This will for example return the following array if you are on the 'about-us' page:

This can be useful if you want to generate a language switcher.

Getting the localized routes for a specific route

You can get the localized routes for a specific route like this:

In this example, the result would be:

This can be useful if you want to tell Google about the other localized versions of a page. (See this article for more information)

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of localization with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
laravel/framework Version ^10.0|^11.0
spatie/laravel-package-tools Version ^1.16
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 outerweb/localization contains the following files

Loading the files please wait ....