Torann / localization by torann

Simple subdomain localization for Laravel.
4,865
2
3
Package Data
Maintainer Username: torann
Maintainer Contact: torann@gmail.com (Daniel Stainback)
Package Create Date: 2016-05-03
Package Last Update: 2024-12-10
Language: PHP
License: BSD-2-Clause
Last Refreshed: 2024-12-18 03:06:12
Package Statistics
Total Downloads: 4,865
Monthly Downloads: 188
Daily Downloads: 12
Total Stars: 2
Total Watchers: 3
Total Forks: 0
Total Open Issues: 0

Laravel Localization - Simplified

Latest Stable Version Total Downloads Patreon donate button Donate weekly to this project using Gratipay Donate to this project using Flattr Donate to this project using Paypal

Simplified localization for Laravel based on the application's subdomain.

Table of Contents

Installation

Composer

From the command line run:

$ composer require torann/localization

Laravel

Once installed you need to register the service provider with the application. Open up config/app.php and find the providers key.

'providers' => [

    \Torann\Localization\LocalizationServiceProvider::class,

]

Publish the configurations

Run this on the command line from the root of your project:

php artisan vendor:publish --provider="Torann\Localization\LocalizationServiceProvider"

A configuration file will be publish to config/localization.php.

Methods

The following methods are available:

Torann\Localization\LocaleManager

  • getNonLocalizedURL($url = null)
  • getDefaultLocale()
  • setLocale($locale = null)
  • localizeURL($locale = null, $url = null)
  • getLocalizedURL($locale = null, $url = null, $attributes = [])
  • getSupportedLocales()
  • getCurrentLocale()
  • getCurrentLocaleDirection()
  • getCurrentLocaleName()
  • getCurrentLocaleNative()
  • getCurrentLocaleScript()
  • getCurrentLocaleNativeReading()
  • getSupportedLanguagesKeys()
  • checkLocaleInSupportedLocales($locale)
  • getConfig($key, $default = null)

Helpers

Laravel Localization comes with a few helper methods

localization()

Returns the Torann\Localization\LocaleManager instance.

localize_url($locale = null, $url = null, $attributes = [])

Returns the given URL adapted to provided locale.

Determining Locale

By Subdomain

For this to work the subdomain needs to match an enabled supported locale key.

By Host

When the given subdomain is determined to not be valid the system can then set the locale depending on the current host. You'll need to set a map of your application's locales to hosts using the hosts configuration option.

License

Localization is open-sourced software licensed under the BSD 2-Clause License.