mvccore/ext-router-module-localization

MvcCore - Extension - Router - Modules With Localization - extension to manage multiple websites in a single project and to manage website localizations (language or language and locale), optionaly contained in a domain or in URL address in the beginning.


Keywords
framework, routing, plugin, mvc, locale, router, extension, routes, modules, language, multiple, localization, plug-in, lang, ext, sites, projects, multi lang, multi language, mvccore, language version, locale version, localized url
License
BSD-3-Clause

Documentation

MvcCore - Extension - Router - Modules With Localization

Latest Stable Version License PHP Version

MvcCore Router extension to manage multiple websites in single project and to manage website localizations (language or language and locale, optionaly contained in URL address domain part or in URL address beinning), defined by domain routes, targeted by module property in URL completing.

This router is the way, how to route your requests in domain level with localization with params or variable sections, namespaces, default param values and more.

Outline

  1. Installation
  2. Features
  3. How It Works
  4. Usage

1. Installation

composer require mvccore/ext-router-module-localization

go to top

2. Features

Extension has the same features as extensions bellow together:

Localization could be contained in any module domain route as param named <localization> match URL requests like this:

  • http://example.com/anything
  • http://en.example.com/anything
  • http://en-US.example.com/anything
  • http://de-DE.example.com/anything
new \MvcCore\Ext\Routers\Modules\Route([
    "pattern"              => "//[<localization>.]example.com",
    "module"               => "main",
    "constraints"          => ["localization" => "-a-zA-Z"],
]);

If there is not contained param <localization> in matched module domain route pattern and matched route (or route to generate URL) is defined as localized route, localization param has to be contained (or is automaticly inserted) in URL address beginning like this:

  • http://example.com/anything
  • http://example.com/en/anything
  • http://example.com/en-US/anything
  • http://example.com/de-DE/anything How precisely is conained in URL address depends on advanced router configuration like allowed languages and more...

go to top

3. How It Works

Extension works in the same way as extensions bellow together:

Router is composed from traits in extensions named above.

go to top

4. Usage

Usage - Bootstrap Initialization

Add this to /App/Bootstrap.php or to very application beginning, before application routing or any other extension configuration using router for any purposes:

$app = \MvcCore\Application::GetInstance();
$app->SetRouterClass('\MvcCore\Ext\Routers\ModuleLocalization');
...
// to get router instance for next configuration:
/** @var \MvcCore\Ext\Routers\ModuleLocalization $router */
$router = \MvcCore\Router::GetInstance();

All other specific usage and advanced configuration is the same as extensions bellow together:

go to top