Download the PHP package jersyfi/laravel-localization without Composer

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

A package to make your application localized

Packagist Downloads Packagist Version GitHub License

Installation

You can install the package via composer

You need to publish the config file to customize the package

You have the option to publish a migration file for adding a customizable column to a users table for storing the current locale for a logged in user. This is usefull if your application wants to send emails to every user.

The published config localization looks like so

How to use

More information can be found in the original Laravel documentation with version 8.x. There you need to know everything about Routing and Localization. When you also want to have translatable models i prefere to use laravel-translatable from Spatie.

Routing

The middleware is using redirect_default to redirect any request when the requested locale was not in locales. To detect the browser language when entering the page for the first time the LocaleController is using detect_locale.

You can redirect to the default_locale by accessing the LocaleController function called localize with the example:

To group a route it is the easiest way to set a prefix named {locale} together with the middleware locale. Inside this group you can set your own localized routes. An example to get this localized route group:

Helpers

The helpers can be accesed directly by aliases or by facades. When using aliases in your controller you need to include use Localization. In below examples the used values are from the above config file so that you can compare it.

Return the given locale or the current app locale with replaced separator.

Return all available locales set in the localization config.

Return application default locale set in the localization config.

Return all available locales from localization config without the default locale.

Return all available locales from localization config without the current locale.

Return the current Route URL

Return the current Route URL with any different locale set in the localization config. The function replaces the {locale} set in routes with the given locale.

Return the current Route URL with default locale set in the localization config.

Check if the locales are valid

Examples

Route to named routes

We create a simple index Route named home calling whatever you want. In this example we call a Controller. Then you can call your route from whereever you want with route('home').

Create a canonical link

You need to call the helper function Localization::currentRouteDefaultLocaleURL()

Create alternate links

To get all alternate links without the default locale you can call the helper function Localization::getLocalesWithoutDefault() inside a foreach loop. Inside the href of the html you can call the helper function Localization::currentRouteLocaleURL() and pass the $locale to it.

Create a language selector

When you want to create a language selector first you need the current locale slug. For this you can call the helper function Localization::getLocaleSlug(). To loop the other locales you can decide if you want to display all available locales with Localization::getLocales() or if you want to display the available locales without the current locale with Localization::getLocalesWithoutCurrent(). Inside the foreach loop you can call the helper function Localization::currentRouteLocaleURL($locale) to get the link and Localization::getLocalSlug($locale) for the locale slug.

Changelog

Please see CHANGELOG for more information what has changed recently.

Credits

License

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


All versions of laravel-localization with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2|^8.0
laravel/framework Version ^8.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 jersyfi/laravel-localization contains the following files

Loading the files please wait ....