Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 8 revisions

Lang_uri Library Supplementary code for URI Language Identifier.

File File:Lang_uri.zip

Installation copy Lang_uri.php to application/libraries Autoload or load whenever needed.

Configuration (config.php) [code] //from ci configuration $config['language'] = "greek";

//added for multilanguage

//for URI Language Identifier ------------- //default language abbreviation $config['language_abbr'] = "el"; //set available language abbreviations $config['lang_uri_abbr'] = array("el" => "greek", "en" => "english"); //ignore this language abbreviation $config['lang_ignore'] = TRUE; // redirect on invalid language abbreviation $config['lang_redirect_url'] = $config['base_url'].$config['index_page']."el/error_404";

//for Lang_uri ------------- $config['lang_ignore_abbr'] = "el"; //language descriptions $config['lang_desc'] = array("el"=>"Ελληνικά","en" => "English"); //language use images $config['lang_useimg'] = TRUE; //or false to use only text //language use images $config['lang_img_path'] = 'img/'; //

//end of multilanguage [/code]

Parameters [quote] uri Leave blank for current url


slug pass array in the format ('lang_abbr'=>'slug-to-add')


stripsegment if needed to delete last segment (when using slug)


exclude_current don't return anything for current language


nolink_current don't return link for current language but display


link_open_tag open tag for link


link_close_tag close tag for link


nolink_open_tag open tag for no link


nolink_close_tag close tag for no link


divider divider, ie '

', leave empty for no use

link_extra_global accepts a string for global link class, ie 'class="lang_links"'


link_extra_lang array for specific lang details ('lang_abbr'=>'class="some" id="en_lang"'), leave empty for no use


lang_useimg Values TRUE/FALSE.if not set it reads setting from config file


lang_img_path path for flag imgs. needs trailing slash. path is absolute (using base_url()). empty for value from config


lang_img_ext file extension for flag imgs. imgs must have the lang_ as filename, ie en.png, el.png, etc [/quote]

Usage. Load your library [code] $this->load->library('lang_uri'); [/code]

To Simply display all language urls of current url use [code] $this->lang_uri->create_links(); [/code]

To add configuration to exclude current Parameters (passed during loading or through initialize function if you are autoloading the library). [code] $config['exclude_current'] = TRUE; $this->lang_uri->initialize($config); $this->lang_uri->create_links(); [/code]

to make the links be ie list items (common use for menus) and assign a class or style in the links [code] $config['link_open_tag'] = '

  • '; $config['link_close_tag'] = '
  • '; $this->lang_uri->initialize($config); $this->lang_uri->create_links(); [/code]

    To use slugs for languages, ie news/article/post-title-in-english, news/article/post-title-in-greek Note if your current url is news/article/post-title-in-english you'll need to set stripsegment to true too.

    [code] $config['stripsegment'] = TRUE; $config['slug'] = array('el' => 'post-title-in-greek', 'en' => 'post-title-in-english'); $this->lang_uri->initialize($config); $this->lang_uri->create_links(); [/code]

    Clone this wiki locally