Download the PHP package hoyvoy/laravel-subdomain-localization without Composer

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

Build Status Codacy Badge StyleCI

Laravel-Subdomain-Localization

Subdomain localization support for Laravel

Laravel laravel-subdomain-localization Lifecycle
^5.5 ^5.5 January 24, 2017
Bug fixes until January 2019
Security fixes until June 2020
^5.6 ^5.6 February 7, 2018
6 months of bug fixes
1 year of security

Table of Contents

Installation

Install with composer

composer require hoyvoy/laravel-subdomain-localization

From Laravel 5.5 onwards, it's possible to take advantage of auto-discovery of the service provider. For Laravel versions before 5.5, you must register the service provider in your config/app.php

Hoyvoy\Localization\LocalizationServiceProvider::class,

Laravel-Subdomain-Localization comes with 2 facades: Localize and Router.

If you want to use them, open config/app.php and add the following lines to the aliases array:

Laravel comes with a middleware that can be used to enforce the use of a language subdomain.

If you want to use it, open app/Http/kernel.php and register this route middleware by adding it to the routeMiddleware array:

Usage

Locale detection

Open app/Providers/RouteServiceProvider.php and add a call to detectLocale() from the boot method. For example, using the facade:

Once you have done this, there is nothing more that you MUST do. Laravel application locale has been set and you can use other locale-dependant Laravel components (e.g. Translation) as you normally do.

Middleware

If you want to enforce the use of a language subdomain for some routes, you can simply assign the middleware provided, for example as follows in app/Http/routes.php:

For more information about Middleware, please refer to Laravel docs.

Route translation

If you want to use translated routes (en.yourdomain.com/welcome, fr.yourdomain.com/bienvenue), proceed as follows:

First, create language files for the languages that you support:

resources/lang/en/routes.php:

resources/lang/fr/routes.php:

Then, here is how you define translated routes in app/Http/routes.php:

You can of course name the language files as you wish, and pass the proper prefix (routes. in the example) to the resolve() method.

Configuration

Configuration file

In order to edit the default package configuration, you can run the following artisan command:

Once you have done that, you will find the config file at config/localization.php.

Configuration values

An array of the locales accepted by the routing system.

Use this option to enable or disable the use of cookies during the locale detection.

Use this option to enable or disable the use of the browser settings during the locale detection.

Here you may change the name of the cookie used to save the locale. This option is used only if localization with cookie is enabled.

Here you may change the name of the domain used in your application. By default, the domain is read from the .env file.

You can specify aliases to use custom subdomains instead of locale codes.

Example: ['german' => 'de'] means that german.mydomain.dev sets locale to de and if locale is set to de, routes will be prefixed with german. instead of de.

Useful functions

The package provides useful functions that you can use - for example - in your views:

Translate current URL

Use Router::current(string $locale) this to generate an alternate version of the current route. This will return an url with the proper subdomain and also translate the uri if necessary.

Get alternate versions of the current URL

Use Router::getCurrentVersions(bool $excludeCurrentLocale = true) to fetch all localized versions of the current route. This will return an array of $locale => $url items that you can use to generate links to alternate versions.

You can pass false as parameter for $excludeCurrentLocale to let function also returns an item for the current locale.

Get localized version for a given route

Use Router::url($routeName, $routeAttributes = null, $locale = null) to generate an alternate version of the given route. This will return an url with the proper subdomain and also translate the uri if necessary.

You can pass route parameters if necessary. If you don't give a specific locale, it will use the current locale.

Changelog

To see what has changed in recent versions, see the CHANGELOG.

License

This package is licensed under the MIT license.


All versions of laravel-subdomain-localization with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.3
illuminate/support Version ^5.6
illuminate/container Version ^5.6
illuminate/events Version ^5.6
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 hoyvoy/laravel-subdomain-localization contains the following files

Loading the files please wait ....