Change website language with Codeigniter

Asked

Viewed 116 times

1

I have a site in Portuguese and French, created two folders within application, being like this.

application/language/portuguese-brazilian
application/language/french

Within it I placed the files in their respective languages.

My doubt is how to dynamically change the language of the user based on the URL he accesses. At the moment I am setting the language like this.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {

    function __construct(){
     parent::__construct();
     $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
     if ($lang == 'pt') {
      $this->lang->load(Array('nav_lang', 'buttons_lang'), 'portuguese-brazilian');
     }elseif ($lang == 'fr') {
      $this->lang->load(Array('nav_lang', 'buttons_lang'), 'french');
}

I needed to check if it is a specific domain, for example dominio.com.fr it redirects me to the French or .br pro Portuguese. In addition I have done by the language of the browser

  • Don’t just take the domain accessed and make the condition such made with the header? I don’t understand exactly what your question is.

  • The doubt is in taking the dominion. I have in config.php a constant APP_URL that me the url of it, local it is localhost/project, need a way to get only the . br or . fr to filter

  • And what is the production value?

  • not yet in production, but it will be something like dominio.com.br and dominio.com.fr

  • So the question boils down to how to extract the last part of a string of the type "dominio.com.br"?

  • Yeah, I don’t know how I’d do with substring

  • Or with a split picking up the 3 parts I don’t know

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.