From 5f88ff35beecaac7aa583765554abce721a3765f Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 18 Dec 2016 15:36:22 +0530 Subject: [PATCH] Add info about midddleware in README --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 7b571d7..91e959c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ This plugins provides: - Route class for generating and matching urls with language prefix. +- Middleware (dispatcher filter or CakePHP < 3.3) which sets `I18n::locale()` + based on language prefix in URL and also provides redirection to appropriate + URL with language prefix when accessing site root. - Class for retrieving translation messages stored in database instead of po/mo files. - Validation class for auto translating validation message. - A widget to generate select box with list of timezone identifiers. @@ -93,6 +96,23 @@ files and populate the translations table. Updating the db records with translations for each language is upto you. Having the messages in a table instead of files make it much to make a web interface for managing translations. +### I18nMiddleware + +You can setup the `I18nMiddleware` in your `src/Application::middleware()` as +shown: + +```php +$middlware->add(new \ADmad\I18n\Middlware\I18nMiddleware([ + 'defaultLanguage' => 'en', + 'languages' => [ + 'en' => ['locale' => 'en_US'], + 'fr' => ['locale' => 'fr_FR'] + ], +])); +``` + +The keys of `languages` array are the language prefixes you use in your URL. + ### TimezoneWidget In your `AppView::initialize()` configure the `FormHelper` to use `TimezoneWidget`.