CAFPE Docs
  • Class

Classes

  • Article_model
  • Articles
  • Auth
  • Auth_controller
  • Bcrypt
  • Hierarchical_controllers
  • Ion_auth
  • Ion_auth_model
  • MY_Controller
  • MY_Lang
  • MY_Model
  • Pages
  • Private_pages
  • Public_controller
  • Seeder
  • Slug
  • User_sessions
  • Users

Functions

  • action_result
  • actions_widget
  • admin_area_buttons
  • base64_current_url_encode
  • base64_url_decode
  • base64_url_encode
  • current_lang
  • jscript_tag
  • lang_switcher
  • logged_in
  • redirect_lang
  • site_url_lang
  • style_tag
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 
<?php defined('BASEPATH') or exit('No direct script access allowed');

function current_lang(){
    $CI =& get_instance();

    return $CI->lang->current;
}

function lang_switcher()
{
    $CI =& get_instance();

    // get languages
    $lang = current_lang();
    $other_lang = $lang === 'es' ? 'en' : 'es';
    // get URI and remove first segment (lang)
    $uri = $CI->uri->segment_array();
    array_shift($uri);
    // public page, Page controller action sould be translated to other language
    if($uri && $uri[0] !== 'admin') {
        $uri[0] = $CI->lang->translate($uri[0], $lang, $other_lang);
    }
    $uri = implode('/',$uri);
    $url = site_url_lang($uri, $other_lang);

    $output = '';
    switch ($lang) {
        case 'es':
            $output .= anchor($url, 'English', 'class="nav-link"');
            break;

        case 'en':
            $output .= anchor($url, 'EspaƱol', 'class="nav-link"');
            break;
    }

    return $output;

}

function site_url_lang($uri, $lang = '', $protocol = null)
{
    return get_instance()->lang->site_url_lang($uri, $lang, $protocol);
}

function redirect_lang($uri = '', $lang = '', $method = 'auto', $code = NULL)
{
    return get_instance()->lang->redirect_lang($uri, $lang, $method, $code);
}
CAFPE Docs API documentation generated by ApiGen