localeurls Automatic locale/language management for URLs

  1. Installation
  2. Changelog

This extension allows to use URLs that contain a language code like

/en/some/page
/de/some/page
http://www.example.com/en/some/page
http://www.example.com/de/some/page

Since 1.1.3 you can also configure friendlier language names if you want:

http://www.example.com/english/some/page
http://www.example.com/deutsch/some/page

The language code is automatically inserted into every URL created and read back on every request. No extra URL rules are required. For best user experience the language is also restored from session/cookie if the user returns to a URL without a language code.

Installation

Extract the package to your protected/extensions directory and rename it to localeurls. Then configure the components in your protected/config/main.php:

<?php
return array(
    // ...
    'components' => array(
        // ...
        'urlManager' => array(
            'class'     => 'ext.localeurls.LocaleUrlManager',

            // Advanced configuration with defaults (see below)
            //'languageParam'   => 'language',
        ),
        'request' => array(
            'class'     => 'ext.localeurls.LocaleHttpRequest',
            'languages' => array('en_us','en','de','fr'),

            // Since version 1.1.3 you can also map url => language
            // 'languages' => array(
            //      'english'   => 'en',
            //      'deutsch'   => 'de',
            //      'fr',
            //  )

            // Advanced configuration with defaults (see below)
            //'persistLanguage'         => true,
            //'languageCookieLifetime'  => 31536000,
            //'redirectDefault'         => false,
        ),
        // ...
    ),
);

Please head over to the github project page for all the details.

Changelog

1.1.6
  • Fix issue where URLs that contained the language code a second time where messed up
1.1.5
  • Fix issue where the query string was lost when switching back to default language
1.1.4
  • Fix issue where you could not create URLs to reset to default language
1.1.3
  • Add mapping feature.
  • Add debug output under category ext.localeurls (only if YII_DEBUG is set)
1.1.2
  • Preferred user language is detected from the HTTP headers now. To disable, set detecLanguage to false in the request component.
1.1.1
  • The parameter defaultLanguage was removed. You should configure the default language in your main application config instead. If you want to redirect to your default language, you can set redirectDefault to true.
5 0
16 followers
1 415 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Tags: I18N, language, url
Developed by: Mike
Created on: Feb 6, 2013
Last updated: 11 years ago

Downloads

show all

Related Extensions