All Projects → Getsupercode → Localizater

Getsupercode / Localizater

Licence: MIT license
Laravel localization package for wrapping routes in multiple locale prefixes

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Localizater

react-translator-component
React language translation module for developing a multilingual project.
Stars: ✭ 13 (-72.92%)
Mutual labels:  multilingual, localization
blazor-ui-messages
Localization messages for Telerik UI for Blazor components: https://www.telerik.com/blazor-ui
Stars: ✭ 24 (-50%)
Mutual labels:  multilingual, localization
f3-multilang
Create multilingual apps with this localization plugin for the PHP Fat-Free Framework
Stars: ✭ 44 (-8.33%)
Mutual labels:  multilingual, localization
Odio
odio is now Strimio!
Stars: ✭ 262 (+445.83%)
Mutual labels:  multilingual, rtl
Localization
🌐 Localization package for Laravel
Stars: ✭ 142 (+195.83%)
Mutual labels:  multilingual, localization
sketch-crowdin
Connect your Sketch and Crowdin projects together
Stars: ✭ 35 (-27.08%)
Mutual labels:  multilingual, localization
react-gettext
Tiny React library for implementing gettext localization in your application.
Stars: ✭ 23 (-52.08%)
Mutual labels:  multilingual, localization
Keys Translations Manager
KTM, a locale management web app built on MERN stack, lets you manage and control locales in one place. It's particularly useful for someone who needs to manage multiple internationalization/localization projects.
Stars: ✭ 81 (+68.75%)
Mutual labels:  multilingual, localization
Bootstrap 3 Arabic
bootstrap 3 arabic
Stars: ✭ 124 (+158.33%)
Mutual labels:  multilingual, rtl
Linguist
Easy multilingual urls and redirection support for the Laravel framework
Stars: ✭ 188 (+291.67%)
Mutual labels:  multilingual, localization
lingua
A PHP-7 language codes converter, from and to the most common formats (ISO or not)
Stars: ✭ 35 (-27.08%)
Mutual labels:  localization, locales
threeBrain
3D Visualization of Brain MRI
Stars: ✭ 29 (-39.58%)
Mutual labels:  localization
laravel-query-localization
Easy Localization for Laravel
Stars: ✭ 50 (+4.17%)
Mutual labels:  localization
laravel-localized-routes
A convenient way to set up and use localized routes in a Laravel app.
Stars: ✭ 257 (+435.42%)
Mutual labels:  localization
bugzilla-tw
Bugzilla traditional Chinese localization files
Stars: ✭ 25 (-47.92%)
Mutual labels:  localization
nestjs-config
NestJS Module for Nonfig services. Nonfig combines Configurations and Features. So you change features, and release swiftly, and measure to digital impact.
Stars: ✭ 40 (-16.67%)
Mutual labels:  localization
EvenVizion
Camera localization and video stabilization component. Fixed coordinates system. Using Python and OpenCV.
Stars: ✭ 38 (-20.83%)
Mutual labels:  localization
routex.js
🔼 Alternative library to manage dynamic routes in Next.js
Stars: ✭ 38 (-20.83%)
Mutual labels:  routes
routes
Google Maps Api test using marker rotation and routes.
Stars: ✭ 38 (-20.83%)
Mutual labels:  routes
enlite-starter
Enlite Starter - React Dashboard Starter Template with Firebase Auth
Stars: ✭ 28 (-41.67%)
Mutual labels:  rtl

Localizater

Latest Version on Packagist Total Downloads Test StyleCI

Laravel package for wrapping routes in multiple locale prefixes.

Installation

Via Composer

composer require getsupercode/localizater

To detect and change the locale of the application based on the request automatically, you can add this middleware to your app/Http/Kernel:

protected $middlewareGroups = [
    'web' => [
        \Getsupercode\Localizater\LocalizaterMiddleware::class,
        // ...
    ]
];

Configuration

By default, the application locales are only going to be en and the default locale is not prefixed. If you want to prefix the default locale, please run the following command to publish the configuration file:

php artisan vendor:publish --provider="Getsupercode\Localizater\LocalizaterServiceProvider" --tag="config"

After installing the package, Adding the middleware and publishing the configuration file. You need to edit the configuration file config/localizater.php in order to add more locales.

Note

The default locale is app.locale located at config/app.php file.

Config: localizater.locales

Add supported locales. It's recommended to write the locale value with its native language.

'locales' => [
    'en' => 'English',
    'fr' => 'Français',
    'ar' => 'العربية',
]

Config: localizater.rtl_locales

Add RTL direction locales.

'rtl_locales' => ['ar']

Config: localizater.prefix_default

If this option is set to true, Default locale URL will be prefixed.

true:
  www.example.com/en
  www.example.com/fr

false:
  www.example.com
  www.example.com/fr

Config: localizater.prefix_default_name

If this option is set to true, Default locale route name will be prefixed.

true:

Method URI URI Name
GET HEAD /page en.page
GET HEAD /fr/page fr.page

false:

Method URI URI Name
GET HEAD /page page
GET HEAD /fr/page fr.page

Usage

The package will not override the route features you already know. It's just a wrapper function that will create multiple locale routes for you.

// routes/web.php

<?php

use Getsupercode\Localizater\Facades\Localizater;
use Illuminate\Support\Facades\Route;

Localizater::group(function () {
    Route::view('/', 'welcome')->name('welcome');

    Route::get('/user', 'UserController@index');
});

// Put other (Non read) route actions outside the `Localizater::group` as you don't need to have multiple locales for those actions.

Route::post('/user', 'UserController@store');

The above example will give us:

Method URI Name
GET|HEAD / welcome
GET|HEAD /fr fr.welcome
GET|HEAD /user
GET|HEAD /fr/user fr.
POST /user

Route naming

If you add a name to a route it will be prepended by the locale key locale.name. for example: (fr.welcome)

All locales without a name will have the same prefix name like fr.. And this is normal as you don't need its names.

Localizater attributes

You can add attributes to the localizer group function as you do with the route group function.

Localizater::group(['middleware' => 'auth'], function () {
    Route::view('/home', 'home')->name('home');
});

Or:

Localizater::group(function () {
    Route::group(['middleware' => 'auth'], function () {
        Route::view('/home', 'home')->name('home');
    });
});

Get route URL in a specified locale

You can get the current route URL in different locale key:

// Current route URL: example.com

locale_route(null, 'fr');

// Output: example.com/fr

Or a named route:

// Route URL: example.com/fr/home

locale_route('home', 'en');

// Output: example.com/home

You can pass the same parameters as the route() function after the locale parameter.

// locale_route($route, $locale, $parameters, $absolute);

// Current route
locale_route(null, 'fr', ['status' => 'active'], true);

// Named route
locale_route('home', 'fr', ['status' => 'active'], true);

Get locale language name

You can get the value of the locale key in localizater.locales configuration for the current locale or a specified locale:

locale_name();
// Output: English

locale_name('fr');
// Output: Français

locale_name('ar');
// Output: العربية

Get HTML dir attribute based on current locale

You can get HTML dir attribute based on current locale. The package will search for RTL locales in localizater.rtl_locales config. If the current locale is listed there, The output will be rtl or ltr if it's not listed.

// Current locale is: ar
locale_dir();
// Output: rtl

// Current locale is: en
locale_dir();
// Output: ltr
<html dir="{{ locale_dir() }}"></html>

You can also get dir attribute for a specified locale:

locale_dir('ar');
// Output: rtl

Change log

Please see the changelog for more information on what has changed recently.

Testing

composer test

Contributing

Please see contributing.md for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

MIT. Please see the 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].