Welcome Guest, Not a member yet? Register   Sign In
Trying to load language file
#1

[eluser]RJ[/eluser]
Hello,

I am receiving an error when switching from English to Spanish:
Quote:Unable to load the requested language file: language/profiler_lang.php

The problem is I don't see where this file is being referenced. Any one have an idea?

Thank you.
#2

[eluser]Krzemo[/eluser]
Just create empty php file it is looking for.
You have profiler on and its looking for it.
#3

[eluser]RJ[/eluser]
Did that, then asked for db_lang.php, added that, now get blank error screen. :/

What doesn't make sense, EN is not looking for those language files and works fine. ES never looked for those files before I added the code below.

libraries/FW_language.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class FW_Language extends CI_Language {

    /**************************************************
     configuration
    ***************************************************/

    // languages
    var $languages = array(
        'en' => 'english',
        'es' => 'spanish'
    );

    // special URIs (not localized)
    var $special = array (
        "admin"
    );
    
    // where to redirect if no language in URI
    var $default_uri = '';

    /**************************************************/
    
    
    function FW_Language()
    {
        parent::CI_Language();        
        
        global $CFG;
        global $URI;
        
        $segment = $URI->segment(1);
        
        if (isset($this->languages[$segment]))    // URI with language -> ok
        {
            $language = $this->languages[$segment];
            $CFG->set_item('language', $language);
        }
        else if($this->is_special($segment)) // special URI -> no redirect
        {
            return;
        }
        else    // URI without language -> redirect to default_uri
        {
            // set default language (first of the array)
            foreach ($this->languages as $lang => $language)
            {
                $CFG->set_item('language', $language);
                break;
            }

            header("Location: ".$this->default_uri, TRUE, 302);
            exit;
        }
    }
    
    
    // get current language
    // ex: return 'en' if language in CI config is 'english'
    function lang()
    {
        $CI =& get_instance();
        $language = $CI->config->item('language');
        $lang = array_search($language, $this->languages);
        if ($lang)
        {
            return $lang;
        }
        
        return NULL;    // this should not happen
    }
    
    
    function is_special($uri)
    {
        $exploded = explode('/', $uri);
        if (in_array($exploded[0], $this->special))
        {
            return TRUE;
        }
        if(isset($this->languages[$uri]))
        {
            return TRUE;
        }
        return FALSE;
    }
    
    
    function switch_uri($lang)
    {
        $CI =& get_instance();

        $uri = $CI->uri->uri_string();
        if ($uri != "")
        {
            $exploded = explode('/', $uri);
            if($exploded[1] == $this->lang())
            {
                $exploded[1] = $lang;
            }
            $uri = implode('/',$exploded);
        }
        return $uri;
    }
    
    function has_language($uri)
    {
        if ($uri != "")
        {
            $exploded = explode('/', $uri);
            if(isset($exploded[1]))
            {
                $segment = $exploded[1];            
                return isset($this->languages[$segment]);                
            }
        }
        return FALSE;
    }
}
// END FW_Language Class

/* End of file FW_Language.php */
/* Location: ./system/application/libraries/FW_Language.php */

And helpers/FW_url_helper.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('site_url'))
{
    function site_url($uri = '')
    {
        $CI =& get_instance();

        // if file or special url
        if($CI->lang->has_language($uri) || $CI->lang->is_special($uri) || preg_match('/(.+)\.[a-zA-Z0-9]{2,4}$/', $uri))
        {
            // do nothing
        }
        else
        {
            // otherwise add language segment
            $lang = $CI->lang->lang();
            $uri = $lang . '/' . $uri;
        }

        return $CI->config->site_url($uri);
    }
}

/* End of file url_helper.php */
/* Location: ./system/application/helpers/FW_url_helper.php */

finally added this to config/routes.php
Code:
// URI like '/en/about' -> use controller 'about'
$route['^fr/(.+)$'] = "$1";
$route['^en/(.+)$'] = "$1";

// '/en' and '/fr' URIs -> use default controller
$route['^fr$'] = $route['default_controller'];
$route['^en$'] = $route['default_controller'];
#4

[eluser]psycho-vnz[/eluser]
If you are testing on Linux OS check the permissions of the files in your language folder




Theme © iAndrew 2016 - Forum software by © MyBB