Taufik Nur Rahmanda
Taufik Nur Rahmanda

Reputation: 1969

CodeIgniter Language Class Library Not Working

I build a website with CodeIgniter 3.1.3 and I want my website have multipe languages, so I tried using language library for the first time by following CI official guide & tutorial from other web, but it's not working as expected.

My application/language/english/slogan_lang.php:

$lang["slogan1"] = "A little social media but with more fun!",
$lang["slogan2"] = "Where face and real name is not important.",
$lang["slogan3"] = "It's a social media. Eh, it's more like a game.",
$lang["slogan4"] = "Fantastic yet fabulous life in a screen.",
$lang["slogan5"] = "Not just poke with one finger, you can duel!",

My controller/index:

public function index() {
    if ($this->session->has_userdata('userid')) redirect('yay/home');
    if (get_cookie('remember_me')!=null) {
        //bla bla bla

        redirect('yay/home');
    } else {
        $this->lang->load('slogan',$this->session->userdata('lang'));
        $data = array();
        $data['lg_slogan'] = array(
            $this->lang->line('slogan1'),
            $this->lang->line('slogan2'),
            $this->lang->line('slogan3'),
            $this->lang->line('slogan4'),
            $this->lang->line('slogan5'),
        );
        $this->load->view('index',$data);
    }
}

$this->session->userdata('lang') ===> 'english'

Result:

$lang arrays echoed behind the navbar

$lang arrays echoed behind the navbar. And $lg_slogan[0] not showing

view source in browser

Where's I do it wrong? Please help.

Upvotes: 0

Views: 945

Answers (1)

Taufik Nur Rahmanda
Taufik Nur Rahmanda

Reputation: 1969

This is absolutely my bad because I wasn't so careful ( ... actually because I'm so sleepy, lol). Anyway, it SOLVED NOW!! There's 2 of my mistake:

  1. I din't type the opening <?php in my slogan_lang.php file
  2. I use comma (,) instead of standard delimiter (;)

That's it, sorry & thank you! :")

Upvotes: 0

Related Questions