All Projects → codezero-be → laravel-localizer

codezero-be / laravel-localizer

Licence: MIT license
Automatically detect and set an app locale that matches your visitor's preference.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-localizer

laravel-localized-routes
A convenient way to set up and use localized routes in a Laravel app.
Stars: ✭ 257 (+655.88%)
Mutual labels:  localization, country, locale
Localizr
Localizr is a Tool that handles and automates the generation of localization files for IOS and Android so there will be only one source of truth for all of your localization strings.
Stars: ✭ 33 (-2.94%)
Mutual labels:  localization, locale
rosetta
A blazing fast internationalization (i18n) library for Crystal with compile-time key lookup.
Stars: ✭ 23 (-32.35%)
Mutual labels:  localization, locale
locale-switcher
Browser Extension to quickly change your browser locale.
Stars: ✭ 75 (+120.59%)
Mutual labels:  localization, locale
Session
A session handler for PHP and Slim 4+
Stars: ✭ 33 (-2.94%)
Mutual labels:  cookie, session
go-locale
GoLang library used to retrieve the current locale(s) of the operating system.
Stars: ✭ 16 (-52.94%)
Mutual labels:  localization, locale
secure-cookie
Secure cookies and sessions for WSGI
Stars: ✭ 30 (-11.76%)
Mutual labels:  cookie, session
CSRF-tutorial
Use Django To Introduce CSRF and Cookies , Session 📝
Stars: ✭ 49 (+44.12%)
Mutual labels:  cookie, session
session
Aplus Framework Session Library
Stars: ✭ 170 (+400%)
Mutual labels:  cookie, session
PHP-Session
PHP library for handling sessions.
Stars: ✭ 54 (+58.82%)
Mutual labels:  cookie, session
Localizr.swift
Simplified and automated Localization process library in IOS. Please check https://github.com/michaelhenry/Localizr for more info.
Stars: ✭ 18 (-47.06%)
Mutual labels:  localization, locale
Cookie Session
Simple cookie-based session middleware
Stars: ✭ 928 (+2629.41%)
Mutual labels:  cookie, session
Silhouette
Silhouette is a framework agnostic authentication library for Scala that supports several authentication methods, including OAuth2, OpenID Connect, Credentials, Basic Authentication or custom authentication schemes.
Stars: ✭ 18 (-47.06%)
Mutual labels:  cookie, session
local.js
Localization script for web sites which has the multiple languages.
Stars: ✭ 15 (-55.88%)
Mutual labels:  localization, locale
nestjs-cookie-session
Idiomatic Cookie Session Module for NestJS. Built on top of `cookie-session` 😻
Stars: ✭ 35 (+2.94%)
Mutual labels:  cookie, session
ocaml-cookie
Working with cookies in OCaml and Reason
Stars: ✭ 31 (-8.82%)
Mutual labels:  cookie, session
awesome-translations
😎 Awesome lists about Internationalization & localization stuff. l10n, g11n, m17n, i18n. Translations! 🌎🌍
Stars: ✭ 54 (+58.82%)
Mutual labels:  localization, locale
cldr-engine
Internationalization and localization in Typescript with Unicode CLDR, batteries included
Stars: ✭ 34 (+0%)
Mutual labels:  localization, locale
cookiet
A small, simple JavaScript cookies library.
Stars: ✭ 13 (-61.76%)
Mutual labels:  cookie
rebar detect
CCFDF rebar detection
Stars: ✭ 14 (-58.82%)
Mutual labels:  detect

Laravel Localizer

IMPORTANT: March 2022

Support Ukraine

It's horrible to see what is happening now in Ukraine, as Russian army is bombarding houses, hospitals and kindergartens.

Please check out supportukrainenow.org for the ways how you can help people there. Spread the word.

And if you are from Russia and you are against this war, please express your protest in some way. I know you can get punished for this, but you are one of the hopes of those innocent people.


GitHub release Laravel License Build Status Code Coverage Code Quality Total Downloads

ko-fi

Automatically detect and set an app locale that matches your visitor's preference.

  • Define your supported locales and match your visitor's preference
  • Uses the most common locale detectors by default
  • Uses the most common locale stores by default
  • Easily create and add your own detectors and stores

Requirements

  • PHP >= 7.1
  • Laravel >= 5.6

Install

composer require codezero/laravel-localizer

Laravel will automatically register the ServiceProvider.

Add Middleware

Add the middleware to the web middleware group in app/Http/Kernel.php, after StartSession and before SubstituteBindings:

protected $middlewareGroups = [
    'web' => [
        \Illuminate\Session\Middleware\StartSession::class, // <= after this
        //...
        \CodeZero\Localizer\Middleware\SetLocale::class,
        //...
        \Illuminate\Routing\Middleware\SubstituteBindings::class, // <= before this
    ],
];

In Laravel 6.x you also need to add the middleware to the $middlewarePriority array in app/Http/Kernel.php to trigger it in the correct order:

protected $middlewarePriority = [
    \Illuminate\Session\Middleware\StartSession::class, // <= after this
    //...
    \CodeZero\Localizer\Middleware\SetLocale::class,
    //...
    \Illuminate\Routing\Middleware\SubstituteBindings::class, // <= before this
];

Publish Configuration File

php artisan vendor:publish --provider="CodeZero\Localizer\LocalizerServiceProvider" --tag="config"

You will now find a localizer.php file in the config folder.

Configure Supported Locales

Add any locales you wish to support to your published config/localizer.php file:

'supported-locales' => ['en', 'nl', 'fr'];

Drivers

Detectors

By default the middleware will use the following detectors to check for a supported locale in:

  1. The URL slug
  2. The session
  3. A cookie
  4. The browser
  5. The app's default locale

If you publish the configuration file, you can choose which detectors to run and in what order.

You can also create your own detector by implementing the \CodeZero\Localizer\Detectors\Detector interface and add a reference to it in the config file. The detectors are resolved from Laravel's IOC container, so you can add any dependencies to your constructor.

Stores

The first supported locale that is returned by a detector will then be stored in:

  • The session
  • A cookie
  • The app locale

If you publish the configuration file, you can choose which stores to use.

You can also create your own store by implementing the \CodeZero\Localizer\Stores\Store interface and add a reference to it in the config file. The stores are resolved from Laravel's IOC container, so you can add any dependencies to your constructor.

Testing

composer test

Security

If you discover any security related issues, please e-mail me instead of using the issue tracker.

Changelog

A complete list of all notable changes to this package can be found on the releases page.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].