Language Switcher

license
GPLv3
version
1.0.4
author
Can Oğuz
Last Updated
16.03.2012

Language Switcher Plugin is a helper plugin for the Multi Language Support extension It is  to create navigation to change site language.

Features

  • Ability to hide segments.
  • Ability to build custom sorted lists.

WARNING

This plugin requires MLS extension to function properly.

Index

Installation

Upload the folder that you have extracted from the downloaded file to your "third_party" folder.

Parameters

  • orderby
    Used to order the menu items.
    language, language_code, language_alias
    Default sorting is the actual order defined in MLS extension settings.
  • remove_segments
    Used to remove unwanted strings from your generated URL. If you want to remove multiple strings you need to separate each item with the | character.
    Accepts any string.
  • show_current
    Used to hide the currently viewed language from the language switching menu.
    yes, no (default value is no)
  • sort
    Defines the sort order.
    asc, desc (default value is asc)

Variables

  • {bbr_segments}
    Outputs all (or filtered) list of URI segments as appear in your URL. i.e. my_template_name/contact/
  • {current_language}
    Outputs the currently selected language's safe name. i.e. turkish
  • {current_language_alias}
    Outputs the currently selected language's public name. i.e. Türkçe
  • {current_language_code}
    Outputs the currently selected  language's code. i.e. tr
  • {total_languages}
    Outputs the total number of languages available in your MLS settings.

Variable Pairs

{lang_loop}{/lang_loop}
With this pair you can loop through all your languages and output all the values you want.

This pair supports the following internal variables:

  • {bbr_count}
    Outputs the incremental count for each language. The count starts with 1.
  • {bbr_lang}
    Outputs the safe name of each language.
  • {bbr_lang_alias}
    Outputs the public name of each language.
  • {bbr_lang_code}
    Outputs the code of each language.
  • {bbr_total}
    Outputs the total number of languages of this loop. This may be different than {total_languages} tag if show_current parameter is set to off.
  • {switch=""}
    This variable is a modifier. It is used to alternate values at each iteration of the list. Each item must be separated with | character.

Usage

Assuming that you have defined three languages Turkish (tr), German (de), French (fr), and English (en); and assuming that you are currently visiting the site in Turkish; the below code


{exp:bbr_langswitcher show_current="no" orderby="language_code" sort="asc" remove_segments="template_group_name"}
<span>Your current language is: {current_language} - {current_language_code}</span>
	{lang_loop} 
          {if "{bbr_count"” == "1"}
            <ul>
	      <li class="first" switch="even|odd">
		<a href="{site_url}{bbr_lang_code}/{bbr_segments}">{bbr_lang}</a>
	      </li>
            </ul>
          {if:elseif ”{bbr_count}” == ”{bbr_total}”
	    <li class="last" switch="even|odd">
		<a href="{site_url}{bbr_lang_code}/{bbr_segments}">{bbr_lang}</a></li>
           {if:else}
	        <li class="{switch=">
		<a href="{site_url}{bbr_lang_code}/{bbr_segments}">{bbr_lang}</a></li>
           {/if} 
         {/lang_loop}
{/exp:bbr_langswitcher}

will output the below HTML:

<span>Your current language is: Turkish - tr</span>
<ul>
	<li class="‘first">
		<a href="“http://yoursite.com/de/”">German</a>
	</li>
	<li class="odd">
		<a href="http://yoursite.com/en/">English</a></li>
	<li class="last">
		<a href="http://yoursite.com/fr/">French</a></li>
</ul>