Download the PHP package pmochine/laravel-tongue without Composer

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

Laravel Tongue πŸ‘… - Multilingual subdomain URLs and redirects

Build Status styleci Scrutinizer Code Quality Coverage Status

Packagist Packagist Packagist

If you are looking for an easy package for subdomain multilingual URLs, this package is for you. 😜

Old Way: https://example.com/de, https://example.com/fr etc.
New Way: https://de.example.com, https://fr.example.com etc.

*Prerequisites*: PHP ^7.4 || ^8.1 and Laravel ^8.41 || PHP ^8.0.2 and Laravel ^9.0 and Laravel ^10.0 Older Laravel Versions**: Click here

Installation in 4 Steps*

1: Add with composer πŸ’»

2: Publish Configuration File (you need to change some things to use it 😎)

3: Add the Middleware 🌐

Laravel Tongue comes with a middleware that can be used to enforce the use of a language subdomain. For example the user calls example.com it goes directly to fr.example.com.

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

4: Add in your Env πŸ”‘

Important! Note the dot before the domain name. Now the session is available in every subdomain πŸ™ƒ. This is important because you want to save all your cookie πŸͺ data in one place and not in many other.

*Note! πŸ“ This step is optional if you use laravel>=5.5 with package auto-discovery feature. Add service provider to config/app.php in providers section

Usage - (or to make it runnable πŸƒβ€β™‚οΈ)

Locale detection πŸ”

Open app/Providers/RouteServiceProvider.php and add this

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-dependent 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 routes/web.php:

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

Frontend 😴

The above <html> tag will always have a supported locale and directionality (β€˜ltr’ or β€˜rtl’). The latter is important for right-to-left languages like Arabic and Hebrew since the whole page layout will change for those.

Configuration

Once you have imported the config file, you will find it at config/localization.php.

Important: Before you start changing the values, you still need to set the "main language" of your page. If your main language is fr, please add this to your config/app.php file under 'fallback_locale' => 'fr',.

We asume that your fallback language has always translated pages. We get the current locale via four ways:

  1. First we determine the local with the subdomain of the URL the user is coming from

If there is no subdomain added, we get the locale from:

  1. an already set language cookie
  2. or the browsers prefered language
  3. or at the end we fall back to the fallback_locale

Note: The value locale in config/app.php has no impact and is going to overwritten by tongue()->detect(); in app/Providers/RouteServiceProvider.php

Configuration values

You don't need to worry about this, only when you are using domains with multiple dots, like: 155ad73e.eu.ngrok.io. Without it, we cannot check what your subdomain is.

Makes the URL BEAUTIFUL πŸ’β€β™€οΈ. ( Use to set fallback language to mydomain.com and not to en.mydomain.com). That is why I even created this package. I just could not find this! 😭

Sometimes you would like to have your admin panel as a subdomain URL. Here you can whitelist those subdomains (only important if those URLs are using the middleware).

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

Use this option to enable or disable the use of cookies πŸͺ during the locale detection.

If you have not changed anything in your middleware "EncryptCookies", you don't need to change anything here as well. More

Important for debugging, when you want to deactivate the middleware speaks-tongue.

Don't say anyone that I copied it from mcamara 🀫

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 routes/web.php:

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

Helper Functions - (finally something useful 😎)

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

Translate your current URL into the given language

Get all translated URL except the current URL

You can pass false as parameter so it won't exclude the current URL.

Translate URL to the language you want

Remember: Set the translation in the lang folder

Use dialect()->translate($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 ☺️.

Redirect URL to the language you want

Use dialect()->redirectUrl($url = null, $locale = null); to redirect for example to the same URL but in different locale. Warning: Works only when the paths are not translated. Use dialect()->translate() for that.

Get your config supported locale list

Remember it returns a collection. You can add methods to it (see available methods) Examples:

Additionally, you can even get some addtional information:

Get the current language that is set

Or if you like you can get the full name, the alphabet script, the native name of the language & the regional code.

How to Switch Up the Language πŸ‡¬πŸ‡§->πŸ‡©πŸ‡ͺ

For example with a selector:

Or in a controller far far away...

Upgrade Guide 🎒

Upgrade to 2.x.x from 1.x.x

There are little changes that might be important for you.

Support for Laravel 9.x.x

If you want to use:

PHP <=8.0 and Laravel 9.x.x

you need to download the version 4.0.0.

Support for Laravel 7.22.0 up to Laravel 8.41.0

If you want to use:

PHP >=7.3 and at least 7.22.0 <= Laravel <=8.41.0

you need to download the version 3.0.0.

Support for Laravel 6.x.x up to Laravel 7.21.0

If you want to use:

PHP >=7.2 and at least 6.x.x <= Laravel <=7.21.0

you need to download the version 2.2.1 or lower.

Support for Laravel 5.x.x

If you want to use:

PHP >=7.0 and at least 5.4 <= Laravel <=5.8

you need to download the version 2.0.0 or lower.

Security

If you discover any security related issues, please don't email me. I'm afraid 😱. [email protected]

Credits

Now comes the best part! 😍 This package is based on

Oh come on. You read everything?? If you liked it so far, hit the ⭐️ button to give me a 🀩 face.


All versions of laravel-tongue with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.1
bakame/laravel-domain-parser Version ^1.0||^1.1
laravel/framework Version ^8.41||^9.0||^10.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 pmochine/laravel-tongue contains the following files

Loading the files please wait ....