• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how i can make content languange file load from database

#1
[eluser]Unknown[/eluser]
such as above topic...

i want to make content of language file load from database

/application/language/english/global_lang.php

Code:
<?php

$lang['indexphp']  = 'index.php/';
$lang['global_telepon']  = '+62(0) 857 3189 9537';
$lang['global_email']  = '[email protected]';

table i want to create like:
Code:
id | indexphp   | global_telepon       | global_email
---------------------------------------------------------------
1  | index.php/ | +62(0) 857 3189 9537 | [email protected]

plzzzz... help me... it's simple for u but not for me...

thanks for helping me... ^^

#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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.