elanguageurlmanager ELanguageUrlManager transparently maps the current application language to the created urls and the other way.

  1. Change log
  2. Examples
  3. Requirements
  4. Usage
  5. How to debug

ELanguageUrlManager transparently maps the current application language to the created urls and the other way around.

  • handles module urls
  • supports "get" and "path" url formats
  • "stateless" working - the extension attempts to maintain the language code in the url without cookies
  • no need to care with language codes in the configured urlmanager rules - mapping is transparent
  • demo method building a basic language selector widget

Change log

1.1

  • fixed the case when the baseUrl member of CUrlManager is empty

Examples

transforming some URLs transparently when the app locale is hu

  • /apps/demo/site/page/view/about -> /apps/demo/hu/site/page/view/about
  • /apps/demo/gii/default/login -> /apps/demo/hu/gii/default/login
  • /apps/demo/index.php?r=site/contact -> /apps/demo/index.php?r=site/contact&lang=hu
  • /apps/demo/?r=gii/default -> /apps/demo/?r=gii/default&lang=hu

Requirements

Yii 1.x

Usage

  1. Place the 2 files in your app's /protected/components directory (or /protected/extensions)
  2. In /protected/config/main.php, configure your app like
'urlManager' => array(
	'class' => 'path.to.your.ELanguageUrlManager',
	'languages' => array('en','hu'),//all languages the app uses
	'langKey' => 'lang',//key of the url param holding the lang.id
	'defaultLang' => false,//default lang.id to carry - will not be visible in the url 
	'stateful' => false, //set to true only if having problems

	//...Add your rules here WITHOUT locale handling eg.
	//
	//'urlFormat' => 'path',
	//'showScriptName' => false,
	//'rules'=>array(
	//	'login'=>'site/login'
	//	...
	//)
),

3. Inherit all controllers of your app from the ELangController class (or at least make sure that the init() and redirect() methods in all controller do the same like ELangControllers' do :-).
4. Test the app, for example, build a language selector somewhere in a layout file by

echo Yii::app()->urlManager->demoLangSelector();

then switch language, navigate over your links.

How to debug

I've placed a log call commented in the line ~225 of ELanguageUrlManager. If you have problems, uncomment this line and check in the app log what new rules have been generated / how the existing rules transformed.

2 0
3 followers
403 downloads
Yii Version: Unknown
License: BSD-2-Clause
Category: Others
Developed by: nlac
Created on: Oct 26, 2013
Last updated: 4 years ago

Downloads

show all

Related Extensions