Welcome Guest, Not a member yet? Register   Sign In
how i can make content languange file load from database
#2

[eluser]yabdab[/eluser]
I was having this same issue and wanted best way to make it work.

I have a cloud service and I want to let all my users have the ability to have custom language values if they want.

I am also using HMVC setup that also presents a wrinkle.

My solution is this, extend the MX_Lang class ( or CI_lang if not using HMVC ).

I create an array of custom line values in an array separate from $this->language ( I call mine _language instead ).

I rework the line() function to look inside my custom array before returning the translation string.

If someone reads this and thinks this is a horrible idea, then please let me know ( and why ). It seems to work OK, but maybe I am missing something?

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

require APPPATH."libraries/MX/Lang.php";

class My_Lang extends MX_Lang {

private $_language = array();

function My_Lang()
    {
        parent::__construct();
      
  log_message('debug', "My_Lang Class Initialized");
  
  $this->_language = array('page_title'=> 'Your Page');
  
}


function line($line = '')
{
  
  $translation = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];

  //print_r($this->language);
  
  // Because killer robots like unicorns!
  if ($translation === FALSE)
  {
   log_message('debug', 'Could not find the language line "' . $line . '"');
  }
  
  // see if there is a customized translation, if so use that instead
  $translation = (isset($this->_language[$line])) ? $this->_language[$line] : $translation;


  return $translation;
}

}
// END My Language Class

/* End of file My_Lang.php */

The custom array can come from a cached dump of a database call or from a direct database call.


Messages In This Thread
how i can make content languange file load from database - by El Forum - 04-24-2012, 12:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB