Download the PHP package laravelista/loki without Composer

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

Loki

Laravel localization done right.

Become a Patron

Overview

If you are building a multilingual website and you need URL management then this is the package for you. It integrates into existing Laravel functionality to support translated URLs and custom locales.

It supports route caching out of the box.

Before, I was using mcamara/laravel-localization to handle this, but I really really needed route caching to work. So, I created this package and simplified the whole setup and integration process.

Whatever mcamara/laravel-localization package can do, Loki can do too, but better.

Features

Installation

From the command line:

Then, add the Loki trait to your RouteServiceProvider class:

If you don't intend to use translated URLs (by default it is set to false) then publish the route file with the command bellow. Otherwise be sure to publish the config file, set useTranslatedUrls to true and create appropriate route files {locale}.web.php.

Publish the localized routes file loki.web.php to your /routes directory:

Now, add $this->mapLocalizedWebRoutes(); to the map method in the RouteServiceProvider.

Installation complete!


Put your localized routes in /routes/loki.web.php file. If you are using translated URLs create a route file for each locale {locale}.web.php (eg. en.web.php). Your non localized routes can remain in the /routes/web.php file. To access non localized routes use URL::getNonLocalizedRoute or URL::getNonLocalizedUrl. See the helpers chapter bellow to find out more.

That's it! View the configuration chapter bellow to configure your preferences.

Configuration

Publish the config file with:

You will find it under config/loki.php.

supportedLocales [array]

Locale names (codes) can be whatever you want.

example. en-GB, hr-HR, en-US, english, croatian, german, de, fr, ...

defaultLocale [string]

The default application locale must be from one of the locales defined in supportedLocales.

hideDefaultLocale [boolean]

If you want to hide the default locale in your URL set this to true. (The default is true.)

example. If your default locale is set to en then requests to URLs starting with /en will be redirected to /.

useTranslatedUrls [boolean]

This enables you to use localized routes. (The default is false.)

If you are using translated URLs for each locale then set this to true.

example. /en/about-us on en locale will be /hr/o-nama on hr locale.

Once this option is set to true you have to create a routes file for each locale with the prefix of the locale.

routes/en.web.php:

routes/hr.web.php:

If you have this enabled, be sure to use route names otherwise it will not work correctly.

Resource routes

If you are using Route::resource and have set useTranslatedUrls to true you will have to set the names for the resource manually or stop using resource mapper and manually map resource routes.

Syntax for the show method, but you can apply the same to others.

en.web.php

hr.web.php

Helpers

The default Laravel helper functions route and url have been changed to support URL localization. So you can use those as you normally would. This enables you to easily swap the mcamara/laravel-localization package with this one. Also, you can install this package, configure your supported locales and your route and URL links will work without the need to change anything.

The bellow helper methods are for edge cases where you want to retrieve the URL for specific locale or just get the current URL in specific locale.

URL::getNonLocalizedRoute($name, $parameters = [], $absolute = true)

It will return the URL for the given route name to the route located in /routes/web.php file.

Don't use the same route names for routes in web.php and loki.web.php.

URL::getNonLocalizedUrl($path, $extra = [], $secure = null)

It will return the URL for the given path as is.

URL::getLocalizedRoute($locale, $name = null, $parameters = [], $absolute = true)

There are two ways of using this method:

  1. Specify just the $locale - it will return the current route in the specified locale
  2. Specify the $locale and the route $name - it will return the URL to the given route name for given locale

If you are using translated routes be sure to use this method if needed.

URL::getLocalizedUrl($locale, $path = null, $extra = [], $secure = null)

There are two ways of using this method:

  1. Specify just the $locale - it will return the current URL in the specified locale
  2. Specify the $locale and the $path - it will return the URL to the given path for given locale

URL::overrideParameters($locale, array|string $parameters)

This method will set the parameters for given locale, so that when method getLocalizedRoute is called it will use these parameters instead of the already present parameters.

Useful for translating slugs. Remember to include all parameters.

Language switcher

Use this blade template snippet to enable users to change the language:

You can modify the template however you want.

Translating URL slugs/parameters

Add this code to your view file inside @php {your code here} @endphp block or inside a controller method where you want to translate slugs:

Replace $model->{'slug_'.$locale} with whatever logic you use to get the translated slug for the model from database.

This method will override the route parameters for given locale, so that the language switcher will return correct URLs with translated slugs.

Sponsors & Backers

I would like to extend my thanks to the following sponsors & backers for funding my open-source journey. If you are interested in becoming a sponsor or backer, please visit the Backers page.

Contributing

Thank you for considering contributing to Loki! The contribution guide can be found Here.

Code of Conduct

In order to ensure that the open-source community is welcoming to all, please review and abide by the Code of Conduct.

License

Loki is open-source software licensed under the MIT license.


All versions of loki with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
illuminate/support Version ^5.7|^6.0|^7.0
illuminate/http Version ^5.7|^6.0|^7.0
illuminate/routing Version ^5.7|^6.0|^7.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 laravelista/loki contains the following files

Loading the files please wait ....